Solved

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

Posted on 2008-06-25
9
1,128 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

746 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

10 Experts available now in Live!

Get 1:1 Help Now