Save image from picture box to hard disk proplem

Posted by Ahmedsa under C# on 6/14/2014 | Points: 10 | Views : 1360 | Status : [Member] | Replies : 5
I using this code to show image in c# 2008

try
{
string[] fileNames = Directory.GetFiles("\\\\192.168.1.5\\Hani");
foreach (string file in fileNames)
{
if (file.Contains(textBox1.Text))
{
pictureBox1.Image = Image.FromFile(Path.Combine("\\\\192.168.1.5\\Hani", textBox1.Text)+".JPG");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString ());
}

it is success in display image but how to save picture in hard disk c drive or d or any location




Responses

Posted by: Goud.Kv on: 6/14/2014 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi Ahmed,

Use Image.Save Method to achieve that..


Thanks & Regards,
Krishna

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ahmedsa on: 6/14/2014 [Member] Starter | Points: 25

Up
0
Down
Thank you for reply

pictureBox1.Image.Save(filePath);
but if i need the user or employee to selecting location or filepath he need to save image in it

dynamically what i write in code



Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Goud.Kv on: 6/14/2014 [Member] [MVP] Gold | Points: 25

Up
0
Down
Try the below code,


public System.Drawing.Image DownloadImageFromUrl(string imageUrl)
{
System.Drawing.Image image = null;
try
{
System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl);
webRequest.AllowWriteStreamBuffering = true;
webRequest.Timeout = 30000;
System.Net.WebResponse webResponse = webRequest.GetResponse();
System.IO.Stream stream = webResponse.GetResponseStream();
image = System.Drawing.Image.FromStream(stream);
webResponse.Close();
}
catch (Exception ex)
{
return null;
}
return image;
}


In the above code, while saving the Image, it will asks the location or path to save..

Thanks & Regards,
Krishna

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ahmedsa on: 6/14/2014 [Member] Starter | Points: 25

Up
0
Down
this for asp.net
but i develop windows application by c# visual studio 2008
how i do it

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Goud.Kv on: 6/14/2014 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi Ahmed,
I don't know developing Windows applications much but, i suggest you to refer below links.
http://stackoverflow.com/questions/22183098/binding-data-from-harddrive-in-windows-store-app
http://stackoverflow.com/questions/21582390/read-and-write-to-and-from-folder-on-hard-disk-without-file-pickers

Thanks & Regards,
Krishna

Ahmedsa, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response