Save jpg on project folder instead of show to user

nauna
 
on May 30, 2016 09:49 AM
3920 Views

Hi,

 

I have this code which is export div data to png its working fine.

I want when click on button div export to png and save it on project folder as image and user just receive message that image save successfully.

 

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
Shashikant
 
on May 30, 2016 09:49 AM

Please share your code

nauna
 
on May 30, 2016 09:56 AM

 

// here is the code

protected void ExportToImage(object sender, EventArgs e)
    {
        string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
        byte[] bytes = Convert.FromBase64String(base64);
        Response.Clear();
        Response.ContentType = "image/png";
        Response.AddHeader("Content-Disposition", "attachment; filename=HTML.png");
        Response.Buffer = true;
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.BinaryWrite(bytes);
        Response.End();
    }

 

Shashikant
 
on May 30, 2016 09:58 AM
on May 30, 2016 10:06 AM

Hi,

Please refer below code

C#

string base64 = Request.Form[hfImageData.UniqueID].Split(',')[1];
byte[] bytes = Convert.FromBase64String(base64);
File.WriteAllBytes(Server.MapPath("~/MyImage/ImageName.jpg"),bytes);

VB

Dim base64 As String = Request.Form(hfImageData.UniqueID).Split(","C)(1)
Dim bytes As Byte() = Convert.FromBase64String(base64)
File.WriteAllBytes(Server.MapPath("~/MyImage/ImageName.jpg"), bytes)

I hope this will help you out.

 

nauna
 
on May 30, 2016 10:03 AM

i have folder name "MyImage" in my project so this code will save the png on my folder shall i replace "Path" with "MyImage" ?

Shashikant
 
on May 30, 2016 10:07 AM

Refer my previous reply i have modified it