SaveFileDialog in C# how to..???

Posted on 2006-05-11
Last Modified: 2008-01-09
i'm use wimform by C#.
i have object SaveFileDialog..
when i get:  
               string path;
               this.path = this.SaveFileDialog.ToString();
 output is:
(example): path  = C:\Document\text.txt

but i want only get part:
                 path = text.txt

How to..??hepl me.
Question by:ncsvietnam
    LVL 12

    Accepted Solution

    after your code:

    path = Path.GetFileName(path);

    (looks a bit funny but the thing is that Path.GetFileName is the function you can use)
    LVL 12

    Expert Comment

    path = system.IO.Path.GetFileName(path);
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    You can also use the FileInfo() class:

            private void button1_Click(object sender, EventArgs e)
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    System.IO.FileInfo fi = new System.IO.FileInfo(saveFileDialog1.FileName);
                    String fileName = fi.Name;
                    String folder = fi.DirectoryName;
                    String fullPath = fi.FullName;
                    MessageBox.Show(fileName + "\n" + folder + "\n" + fullPath);

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now