Solved

ASP.NET Form Export to Word CSS Settings

Posted on 2011-09-22
2
420 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

735 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