Solved

how do i get path of the saved file using saveFileDialog to create Bakcup Files....

Posted on 2008-06-25
9
1,134 Views
Last Modified: 2013-12-16
I want to get path of the saved file using saveFileDialog to create backup file....txtField must have the path to create backup...

private void btnBackupEngagement_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            Backup.Backup bck = new Adra.Backup.Backup();
            DsAmDb ds = bck.GetEngDataSet(myOper);
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Encoding = Encoding.Default;
            settings.Indent = true;            
            //string path = txtBackupFilePath.Text.ToString().Trim();
            string path = Path.GetFullPath(???);
            //if ( txtBackupFilePath.Text.ToString().Trim() == "")
            if (txtBackupFilePath.Text.LastIndexOf('\\') != 0)
            {
               

                //if ( txtBackupFilePath.Text.ToString().Trim() == "")
                if (path.ToString().Trim() == "")
                {
                    MessageBox.Show("Please select a folder to save backup file.");
                    return;
                }
                else
                {
                    //string path = txtBackupFilePath.Text.Substring(0, txtBackupFilePath.Text.LastIndexOf('\\'));
                    if (txtBackupFilePath.Text != "")
                    {
                        if (Directory.Exists(path) == true)
                        {
                            if (MessageBox.Show(GetValue("thefolder") + " " + path + " " + GetValue("doesnotexist") + "." + "\r\n" + GetValue("doyouwishtocreatefolder"), GetValue("info"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                Directory.CreateDirectory(path);
                            }
                            else
                            {
                                this.Cursor = Cursors.Default;
                                return;
                            }
                        }
                    }

                }


             
            }

***********************************Her is SaveFileDialog function********************************
private void button1_Click(object sender, EventArgs e)
        {
            String fileName = "Bakcup ";
            DateTime currentDateTime = DateTime.Now;
            String dateStr = currentDateTime.ToString(fileName + "yyyy-MM-dd hh-mm-ss");
            Stream myStream;
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();
           
            //saveFileDialog1.Filter = "txt files (*.xml)|*.xml(*.txt)|*.txt|All files (*.*)|*.*";
            saveFileDialog1.Filter = "File Type (*.xml)|*.xml";
            saveFileDialog1.FilterIndex = 2;
            saveFileDialog1.RestoreDirectory = true;
           
            saveFileDialog1.FileName = fileName;
            saveFileDialog1.FileName = dateStr;

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((myStream = saveFileDialog1.OpenFile()) != null)
                {
                    // Code to write the stream goes here.
                    //this.lblBackupPath.Text = "c:\tmp";
                    //StreamWriter writer = new StreamWriter(myStream);
                    //writer.Write("Hello World");
                    txtBackupFilePath.Text = dateStr;
                    myStream.Close();
                }
            }

0
Comment
Question by:Adnan
  • 5
  • 4
9 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 21864146
           if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                label1.Text = System.IO.Path.GetDirectoryName(saveFileDialog1.FileName);
0
 
LVL 17

Expert Comment

by:mokule
ID: 21864241
Maybe I misunderstood at first.
Maybe You should use

            folderBrowserDialog1.ShowDialog();
0
 

Author Comment

by:Adnan
ID: 21864353
not working, i tried with this code: string path = System.IO.Path.GetDirectoryName(saveFileDialog1.FileName + dateStr);

the directory path is C:\tmp and i want to get the saved files path to create backup.
0
 

Author Comment

by:Adnan
ID: 21864357
filename is i like this : Bakcup 2008-06-25 09-58-03
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:Adnan
ID: 21864412
i can explain litle more....when i click on browse button i will get SaveFileDialog window up, with the file name : Bakcup 2008-06-25 09-58-03, and when i click the save button the file wil be saved as a xml file in the folder. then when i click to create backup it must get the path of the file to createtd and the path is c:\tmp\Bakcup 2008-06-25 09-58-03
0
 

Author Comment

by:Adnan
ID: 21864458
i get this Exception message: The path is not of a legal form.
0
 
LVL 17

Expert Comment

by:mokule
ID: 21864461
This function
System.IO.Path.GetDirectoryName(saveFileDialog1.FileName)
gives You the saved file path.
I don't know what is Your problem then.
0
 
LVL 17

Expert Comment

by:mokule
ID: 21864494
string path = System.IO.Path.GetDirectoryName(saveFileDialog1.FileName + dateStr);

should be rather

string path = System.IO.Path.GetDirectoryName(saveFileDialog1.FileName) + dateStr;
0
 
LVL 17

Accepted Solution

by:
mokule earned 500 total points
ID: 21864567
if dateStr doesn't contain \ at the brginning it should be
string path = System.IO.Path.GetDirectoryName(saveFileDialog1.FileName) + "\\" + dateStr;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

911 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

20 Experts available now in Live!

Get 1:1 Help Now