Solved

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

Posted on 2008-06-25
9
1,175 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

759 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