Solved

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

Posted on 2008-06-25
9
1,191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

 

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

Enroll in July's Course of the Month

July's Course of the Month is now available! Enroll to learn HTML5 and prepare for certification. It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

623 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