Goal:
– Save a picture from my computer’s harddrive to the WPF’s application.
– After adding a picture, you are enable to view the picture in visual Studio after updating the solution and projects.
Problem:
I don’t know HOW to save a picture inside of my WPF’s application. To
be more specificed I want the picture to be saved in the map
ArticlePicture from project DataAccessLibrary.
Again, I know how to do it in ASP.net MVC but not in WPF application. The syntax from MVC doesn’t work in WPF application.
Please remember that the picture is not directly from the Internet. I upload the picture directly from my personal computer to the WPF application. The WPF application is stored in my personal PC.
The input data of the picture take place in the project MediaStore
The directory address of the picture is:
“C:\Users\Fullmetalboy\Desktop\Firefox download\picture.gif”
Directory address of the project and its map ArticlePicture is:
“E:\Project\MediaStore\DataAccessLibrary\ArticlePicture\”
The goal is to add and copy the picture to the map “ArticlePicture” with this new address
“E:\Project\MediaStore\DataAccessLibrary\ArticlePicture\picture.gif
I have tried these links but unfortunately, it didn’t provide me any success.
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapsource.aspx
http://msdn.microsoft.com/en-us/library/ms748873.aspx#_imageformats
Syntax code in WPF application
private void btnBrowse_Click(object sender, RoutedEventArgs e)
{
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.Filter = "jpg files (*.jpg)|*.jpg|gif files (*.gif)|*.gif|jpeg files (*.jpeg)|*.jpeg";
dlg.Multiselect = false;
bool? result = dlg.ShowDialog();
if (result == true)
{
Stream fInfo = dlg.OpenFile();
using (System.Drawing.Image correctPicture = System.Drawing.Image.FromStream(fInfo))
{
if (correctPicture.Width <= 180 && correctPicture.Height <= 250)
{
var fileName = System.IO.Path.GetFileName(dlg.FileName);
var path = System.IO.Path.Combine(Server.MapPath("/Content/Images/"), fileName);
}
else
{
}
}
}
}
Syntax code in ASP.net mVC //
// POST: /Admin/Produkt_ListaCreate/
[HttpPost, Authorize(Roles = "Admin")]
public ActionResult Produkt_ListaCreate(Bok pMyBok, HttpPostedFileBase file)
{
if (file != null)
{
using (System.Drawing.Image correctPicture = System.Drawing.Image.FromStream(file.InputStream))
{
if (correctPicture.Width <= 180 && correctPicture.Height <= 250)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("/Content/Images/"), fileName);
file.SaveAs(path);
pMyBok.BokBildUrl = "/Content/Images/" + fileName;
}
else
{
TempData["message"] = "Den uppladdade bilden fungerar inte pga att den uppfyller inte storlekens och formatets kriterier.";
return RedirectToAction("index");
}
}
} // if (file != null)
_myIBookRepository.Add(pMyBok);
_myIBookRepository.Spara();
TempData["message"] = "En boken är skapad.";
return View("index");
}

Server.MapPath is not going to work in a WPF application – its for IIS applications.
Where does this WPF application run? If its running from the same machine, what directory is it being run from? You need some way for the WPF application to determine where the ArticlePicture directory resides.
Assuming you are running the WPF application from the web server, you know where the directory resides, and the WPF application has permissions to access the directory, then all you need to do is to a file copy operation. (I see no reason to save the file back out of the WPF application if it is not modified).
I suspect maybe your intention is to upload the picture to the website via the WPF application. If so you might need to explain more clearly.