Solved

ASP.NET Form Export to Word CSS Settings

Posted on 2011-09-22
2
419 Views
Last Modified: 2012-05-12
Hello Experts,

I have a button click event that will export my datagrid to a word document. The code works to bring the information out, but it is not applying my css styles that I have defined. Is there a way that I can replace the css style that is created with the export my css defined in the /Portals/0/portal.css file. (see attached code for button click).
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        Response.AddHeader("content-disposition", "attachment;filename=Export.doc")
        Response.Cache.SetCacheability(HttpCacheability.NoCache)
        Response.ContentType = "application/vnd.word"

        Dim stringWrite As New System.IO.StringWriter()
        Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
        Dim fi As FileInfo = New FileInfo(Server.MapPath("Portals/0/portal.css"))

        Dim sb As New System.Text.StringBuilder
        Dim sr As StreamReader = fi.OpenText()
        Do While sr.Peek() >= 0
            sb.Append(sr.ReadLine())
        Loop
        sr.Close()

        ' Create a form to contain the grid
        Dim frm As New HtmlForm()
        applicationGrid.Parent.Controls.Add(frm)
        frm.Attributes("runat") = "server"
        frm.Controls.Add(applicationGrid)
        frm.RenderControl(htmlWrite)

        Response.Write(stringWrite.ToString())
        Response.[End]()
    End Sub

Open in new window

0
Comment
Question by:NursingCorp
2 Comments
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
ID: 36585211
0
 

Author Closing Comment

by:NursingCorp
ID: 36586720
I ended up iterating through the grid and placing each row into a string, then assigning that string to a Label, and using the code from the link provided to pull in my style sheet.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question