Can anyone please tell whether I can find the filesize, extension, mime type of a file using open file dialog ctrl?
Can anyone please tell whether I can find the filesize, extension, mime type of a file using open file dialog ctrl?
You can find it here.
Use a FileInfo object could be a possibility....
So something like:
Or you would just split on the last . that occurs in the filename. I don't know what other kind of info or actions a fileinfo object implements, for more info im glad I can direct you to http://msdn.microsoft.com/library/de...classtopic.aspCode:private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { FileDialog s = (FileDialog)sender; this.file = new FileInfo(s.FileName.ToString()); MessageBox.Show(file.Extension.ToString()); }
:edit:
Wraithan, I almost forgot about that cool search engine everyone is talking about. It's supposed to be the latest fashion on the net but I havent tried it yet, seems promising though.
This is relatively trivial, but it's worth mentioning. According to Microsoft's event standards, it's considered really bad to cast the sender parameter and use it. The only thing you should do with that object is possibly a ReferenceEquals. Consider for yourself whether or not this is a good practice.Originally Posted by GanglyLamb
Also, I probably wouldn't split on . for the extension. You can use Path.GetExtension(string) to get an extension.
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein
Thanks a ton guys...but I cannot get the mime type like this.Right?
Well normally I would not cast the sender as well ( as in I must admit that this is a wrong place to put an explicit cast in this example ). But I figured the OP would see this as well , and with a straight copy paste of code, this would definately be worth mentioning by the one reviewing this code ( I know I can be a bastard at times ).
The only time I've used an explicit cast like this from an event's sender was when I was using a 2D array of buttons for my minesweeper clone. Since every button had the same event handler, and I needed to know which button was pressed, so I needed the button properties of the sender for this to correctly adjust the field and start uncovering some squares...
It's too bad I'm not in touch with more C# programmers like you, there are definately some things one could learn from the other , or maybe I should just look at more C# boards like this one ... ( and I finished my C# course *sigh* next year course of programming is ASP.NET - and I'm not really looking forward to it but anyway if that's what people want then that's what I'll be doing... ).
Aye. I haven't gone looking for C# boards because I like the community structure here. Unfortunately, we just don't have many C# programmers.Originally Posted by GanglyLamb
Don't fret much about ASP.Net. You can use either C# or VB.Net to do your server-side programming, so you can still work in C#.
If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein