Solved

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

Posted on 2008-06-25
9
1,143 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

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

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

813 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

11 Experts available now in Live!

Get 1:1 Help Now