Skip to main content

Dynamic Image Url Code Behind Code To Export Multiple Images to Word File

[vb.code]
* Write This Code in Button Click Event.
*  img1,2,3,4 variable is used to get and store the image name which is stored in the session.
* My Scenario was export all four chart control images into one ms-word file.
* Here all image name are unique and stored into the session variable.


Protected Sub btnExportAllChart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportAllChart.Click
   
        Dim serverurl As String =   Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath + "/TempImageFiles/"
        Dim img1 As String = serverurl + Session("ImageName1")
        Dim img2 As String = serverurl + Session("ImageName2")
        Dim img3 As String = serverurl + Session("ImageName3")
        Dim img4 As String = serverurl + Session("ImageName4")
        HttpContext.Current.Response.Clear()
        HttpContext.Current.Response.Charset = ""
        HttpContext.Current.Response.ContentType = "application/msword"
        Dim strFileName As String = FileName+ ".doc"
        HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=" + strFileName)
        Dim strHTMLContent As New StringBuilder
       
       
strHTMLContent.Append("<table align='Center'>".ToString())

        strHTMLContent.Append("<tr>".ToString())
        strHTMLContent.Append("<td>".ToString())
        strHTMLContent.Append("<img src='" + img1 + "' width='500' height='400'/>".ToString())
        strHTMLContent.Append("</td>".ToString())
        strHTMLContent.Append("<td>".ToString())
        strHTMLContent.Append("<img src='" + img2 + "' width='500' height='400'/>".ToString())
        strHTMLContent.Append("</td>".ToString())
        strHTMLContent.Append("</tr>".ToString())
       
strHTMLContent.Append("<tr>".ToString())
        strHTMLContent.Append("<td>".ToString())
        strHTMLContent.Append("<img src='" + img3 + "' width='500' height='400'/>".ToString())
        strHTMLContent.Append("</td>".ToString())
        strHTMLContent.Append("<td>".ToString())
        strHTMLContent.Append("<img src='" + img4 + "' width='500' height='400'/>".ToString())
        strHTMLContent.Append("</td>".ToString())
        strHTMLContent.Append("</tr>".ToString())
     
        strHTMLContent.Append("</table>".ToString())
        HttpContext.Current.Response.Write(strHTMLContent)
        HttpContext.Current.Response.End()
        HttpContext.Current.Response.Flush()
    End Sub

OutPut:

Comments

Popular posts from this blog

Visual Studio 2010 Error HRESULT E_FAIL has been returned from a call to a COM component.

I was using Visual Studio 2010.  I was debugging a web application and an exception happened and VS 2010 froze.  I ended the VS 2010 in the task manager and when I went back to developing, I found on every form for every ASP.net control I get:  Error Creating Control - Error HRESULT E_FAIL has been returned from a call to a COM component.  Also I am unable to edit  the form or add anything from the toolbox. Solution: This error comes because of Caching of Visual Studio Delete the Cache. You can delete the project cache at "Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache", then run "devenv /setup" to build the cache again to see if it helps.

Password Protected File Validation for(.doc/.docx/.xls/.xlsx/.pdf) file types

Password Protected File Validation for(.doc/.docx/.xls/.xlsx/.pdf) file types protected void btnUpload_Click( object sender, EventArgs e)         {             //Check if File Upload control has file or not             if (FileUpload1.HasFile)             {                 //Get Uploaded file bytes                 var bytes = FileUpload1.FileBytes;                 //Get Uploaded File Extension                 FileInfo objFileInfo = new FileInfo (FileUpload1.FileNam...

PDF Editor

http://www.pdfescape.com PDFescape is a free, online PDF reader, editor, form filler, & form designer. Free PDF Reader Free PDF Editor Free PDF Form Filler Free PDF Form Designer Free Webmaster Tools No Downloads No Watermarks A new way to open and edit PDF files online, PDFescape frees users from the typical software requirements for using the de facto document file format. Completely online, PDFescape requires no more than a modern internet browser and an active internet connection. Select any of the major features above to learn more.