none
saving Image To Application Folder and Retriving RRS feed

  • Question

  • Hi,
        I need to save an Image to application folder and as well as retrive it .
    Any Advice ot link would be helpful
    Friday, July 3, 2009 9:52 AM

Answers

  • if you are using asp.net then read this article
    http://www.dotnetcurry.com/ShowArticle.aspx?ID=129&AspxAutoDetectCookieSupport=1

    in this you create an HTTP handler to display a saved image

    if you are using windows application please tell and I will get u the code; I have it in one of my projects - i have to search for it
    • Marked as answer by dillu Tuesday, January 5, 2010 10:45 AM
    Monday, July 6, 2009 12:44 PM
  • if you are using windows application then you should have a picture box
    to retrieve the image
    you set the prperty of the picture box Image
    for example
    pictureBox.image = Bitmap.FromFile(openFileDialog.FileName);

    where openFileDialog is a component that can be found on the toolbox menu

    now to save the image

    Bitmap image = new Bitmap((System.Drawing.Image)pictureBox.image);
    MemoryStream imageStream = new MemoryStream();
    image.Save(path,imageStream,System.Drawing.Imaging.ImageFormat.Jpeg);

    where path is the location that you want to save the image to

    if you want to save the image to a database then
    byte[] imageArr = imageStream.GetBuffer();

    now this array of byte you can set it as a value of an SqlParameter of type Varbinary or Image

    Inform me if you want detailed code
    • Proposed as answer by alihijazi Monday, July 6, 2009 1:14 PM
    • Marked as answer by Zhi-Xin Ye Thursday, July 9, 2009 1:22 PM
    Monday, July 6, 2009 1:01 PM

All replies

  • If u r using Windows application, u can use save file dialog to save the file.
    If u have the file present in predefined path, u can use File.Copy() to save to a particular path.

    "Application.ExecutablePath" will give u the application folder path where "Application" is a class in System.Windows.Form and "ExecutablePath" is a property.

    Directory.GetCurrentDirectory() will also give the current directory of ur application.

    Hope it helps.

    Regards,
    Renil

    Friday, July 3, 2009 10:28 AM
  • if you are using asp.net then read this article
    http://www.dotnetcurry.com/ShowArticle.aspx?ID=129&AspxAutoDetectCookieSupport=1

    in this you create an HTTP handler to display a saved image

    if you are using windows application please tell and I will get u the code; I have it in one of my projects - i have to search for it
    • Marked as answer by dillu Tuesday, January 5, 2010 10:45 AM
    Monday, July 6, 2009 12:44 PM
  • if you are using windows application then you should have a picture box
    to retrieve the image
    you set the prperty of the picture box Image
    for example
    pictureBox.image = Bitmap.FromFile(openFileDialog.FileName);

    where openFileDialog is a component that can be found on the toolbox menu

    now to save the image

    Bitmap image = new Bitmap((System.Drawing.Image)pictureBox.image);
    MemoryStream imageStream = new MemoryStream();
    image.Save(path,imageStream,System.Drawing.Imaging.ImageFormat.Jpeg);

    where path is the location that you want to save the image to

    if you want to save the image to a database then
    byte[] imageArr = imageStream.GetBuffer();

    now this array of byte you can set it as a value of an SqlParameter of type Varbinary or Image

    Inform me if you want detailed code
    • Proposed as answer by alihijazi Monday, July 6, 2009 1:14 PM
    • Marked as answer by Zhi-Xin Ye Thursday, July 9, 2009 1:22 PM
    Monday, July 6, 2009 1:01 PM