urgent copy image from hard Drive on local host
-
am developing application in ASP.Net with C#. i am using button for FileOpenDialog to browse any image from hard drive as follows openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; problem is: i want the browsed image to be copied in local hosti.e,""C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg" i have the follwing idea in mind File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); or File.Copy(s.Substring(13,s.Length-13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); but i dont want to existing image to be overwrite, i want all images to ve saved in local host can anyone sugesst me what to do?
-
am developing application in ASP.Net with C#. i am using button for FileOpenDialog to browse any image from hard drive as follows openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; problem is: i want the browsed image to be copied in local hosti.e,""C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg" i have the follwing idea in mind File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); or File.Copy(s.Substring(13,s.Length-13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); but i dont want to existing image to be overwrite, i want all images to ve saved in local host can anyone sugesst me what to do?
If you use File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); it will throw IOException if the destination already exists so you should check that before you start copying. What so you want to do if the file already exists? I suggest you give them all unique name using GUID.
#region signature my articles #endregion
-
If you use File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); it will throw IOException if the destination already exists so you should check that before you start copying. What so you want to do if the file already exists? I suggest you give them all unique name using GUID.
#region signature my articles #endregion
-
will u plz make ur sugesstion some more clear that "give them all unique name using GUID" GUID?
He means that the Guid type is guaranteed to generate a unique value, so there is no danger of overwriting files. For instance:
string fileDest = Path.Combine(@"c:\Images\Copy", Guid.NewGuid().ToString() + ".gif"); File.Copy(@"c:\Images\MyImage.gif", fileDest);
Deja View - the feeling that you've seen this post before.
-
He means that the Guid type is guaranteed to generate a unique value, so there is no danger of overwriting files. For instance:
string fileDest = Path.Combine(@"c:\Images\Copy", Guid.NewGuid().ToString() + ".gif"); File.Copy(@"c:\Images\MyImage.gif", fileDest);
Deja View - the feeling that you've seen this post before.
can u suggest a solution for following problem public static int count = 0; private void button3_Click_1(object sender, EventArgs e) { openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; string st = "Pict" + (count++) + ".jpg"; File.Copy(s.Substring(13, s.Length - 13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\" + st);} i want the image to be saved in local host with the same name as as it was present in hard drive (from where it was browsed) i have applied ur GUID example but unfortunately its not working, can u apply this in my code?
-
can u suggest a solution for following problem public static int count = 0; private void button3_Click_1(object sender, EventArgs e) { openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; string st = "Pict" + (count++) + ".jpg"; File.Copy(s.Substring(13, s.Length - 13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\" + st);} i want the image to be saved in local host with the same name as as it was present in hard drive (from where it was browsed) i have applied ur GUID example but unfortunately its not working, can u apply this in my code?
-
can u suggest a solution for following problem public static int count = 0; private void button3_Click_1(object sender, EventArgs e) { openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; string st = "Pict" + (count++) + ".jpg"; File.Copy(s.Substring(13, s.Length - 13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\" + st);} i want the image to be saved in local host with the same name as as it was present in hard drive (from where it was browsed) i have applied ur GUID example but unfortunately its not working, can u apply this in my code?
You can't keep the filenames the same - you are going to have to change them somehow. The Guid example would be:
string s = System.IO.Path.GetFileName(openFileDialog1.FileName); string st = "Pict" + Guid.NewGuid().ToString() + ".jpg"; File.Copy(openDialog1.Filename, Path.Combine(@"c:\inetpub\wwwroot\15 website\images", st));
Deja View - the feeling that you've seen this post before.
-
am developing application in ASP.Net with C#. i am using button for FileOpenDialog to browse any image from hard drive as follows openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; problem is: i want the browsed image to be copied in local hosti.e,""C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg" i have the follwing idea in mind File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); or File.Copy(s.Substring(13,s.Length-13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg"); but i dont want to existing image to be overwrite, i want all images to ve saved in local host can anyone sugesst me what to do?
If you get the solution can you please post it on all the forums your posted this question.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
-
You can't keep the filenames the same - you are going to have to change them somehow. The Guid example would be:
string s = System.IO.Path.GetFileName(openFileDialog1.FileName); string st = "Pict" + Guid.NewGuid().ToString() + ".jpg"; File.Copy(openDialog1.Filename, Path.Combine(@"c:\inetpub\wwwroot\15 website\images", st));
Deja View - the feeling that you've seen this post before.
string strQuery = ""; openFileDialog1.ShowDialog(); string s = openFileDialog1.FileName; textBox6.Text = s; st2 = s; string st = "Pict" + Guid.NewGuid().ToString() + ".jpg"; File.Copy(openFileDialog1.FileName, Path.Combine(@"c:\inetpub\wwwroot\15 website\images", st)); strQuery = "INSERT INTO criminal(pic_name) VALUES('"+System.IO.Path.GetFileName(openFileDialog1.FileName)+"')"; SqlCommand com = new SqlCommand(strQuery, conn); com.ExecuteNonQuery(); PROBLEM: error comes on this the SQL Query , am i inserting rightly? or there is some other way Actually i want to insert only picture name of the picture to be browsed can u plz suggest any solution