Thread: open file dialog

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    141

    open file dialog

    Can anyone please tell whether I can find the filesize, extension, mime type of a file using open file dialog ctrl?

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    You can find it here.

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    Use a FileInfo object could be a possibility....

    So something like:

    Code:
            private void openFileDialog1_FileOk(object sender, CancelEventArgs e) {
                FileDialog s = (FileDialog)sender;
                this.file = new FileInfo(s.FileName.ToString());
                MessageBox.Show(file.Extension.ToString());
            }
    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.asp

    :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.

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by GanglyLamb
    Code:
            private void openFileDialog1_FileOk(object sender, CancelEventArgs e) {
                FileDialog s = (FileDialog)sender;
                this.file = new FileInfo(s.FileName.ToString());
                MessageBox.Show(file.Extension.ToString());
            }
    Or you would just split on the last . that occurs in the filename.
    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.

    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

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    141
    Thanks a ton guys...but I cannot get the mime type like this.Right?

  6. #6
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    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... ).

  7. #7
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by GanglyLamb
    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.

    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM