Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP.NET Form Export to Word CSS Settings

Posted on 2011-09-22
2
Medium Priority
?
439 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

618 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