Vivek Thakur

Chaotically Complex

  Home  |   Contact  |   Syndication    |   Login
  102 Posts | 1 Stories | 317 Comments | 66 Trackbacks

News



Archives

ASP.NET Ventures

Many times we would like to export our page as an Excel sheet, Word doc or PDF file. This can be simply achieved by changing the ContentType of the Response object and overriding the RenderControl method of the control to be exported:

Page Load()
{
 //bind data to data bound controls and do other stuff

Response.Clear(); //this clears the Response of any headers or previous output
Response.Buffer = true; //make sure that the entire output is rendered simultaneously

///
///Set content type to MS Excel sheet
///Use "application/msword" for MS Word doc files
///"application/pdf" for PDF files
///

Response.ContentType = "application/vnd.ms-excel";
StringWriter stringWriter = new StringWriter(); //System.IO namespace should be used

HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

///
///Render the entire Page control in the HtmlTextWriter object
///We can render individual controls also, like a DataGrid to be
///exported in custom format (excel, word etc)
///
this.RenderControl(htmlTextWriter);
Response.Write(stringWriter.ToString());
Response.End();
} //end page load

For exporting ASP.NET pages as PDF files, you need to know the Adobe PDF specs for generating the PDf correctly. There is already a wonderful component which does the same and its free! See this article along with sample source code on how to export a page to PDF:

http://www.codeproject.com/cs/library/giospdfnetlibrary.asp

Hope this would be helpful...!

posted on Tuesday, September 26, 2006 1:13 PM

Feedback

# re: Export ASP.NET page to Word, Excel or PDF 10/3/2006 8:54 AM AzamSharp
Hi,

I don't think it works with the pdf files!

Thanks,
Azam

# re: Export ASP.NET page to Word, Excel or PDF 10/3/2006 11:32 AM Vivek Thakur
Hi Azam,

You are right. My bad that I missed out a few lines. Have added them now.

Thanks for pointing this out,

Vivek

# re: Export ASP.NET page to Word, Excel or PDF 11/22/2006 12:43 PM Amit Thakur
Hi, I tried above code for generating pdf file.
But not able to do so.
Can you tell whether its working for you (in case of pdf) or not.
Also if its working for can you post sample code here.
I am using ASP.Net 1.1 and VB.Net.

Waiting for reply
Bye
Amit

# re: Export ASP.NET page to Word, Excel or PDF 11/22/2006 3:06 PM Vivek
Amit,

Did you try this link for pdf generation?
http://www.codeproject.com/cs/library/giospdfnetlibrary.asp

Let me know if this is not working.

Vivek

# re: Export ASP.NET page to Word, Excel or PDF 2/21/2007 5:50 PM Bharath
i cant impliment this coad even for word export to

Please tell me how to use it ASAP

# re: Export ASP.NET page to Word, Excel or PDF 2/27/2007 5:01 PM Karthik
Hi ,

I was not able to view the generated excel file . Following error occurred "Unable to read the file" . Let me know if u have any answers ....

# re: Export ASP.NET page to Word, Excel or PDF 3/1/2007 10:10 AM Vivek
Hi Bharath,

The code is working for Word at my end. Let me know what problems you are facing.

Vivek

# re: Export ASP.NET page to Word, Excel or PDF 3/1/2007 10:11 AM Vivek
Karthik,

May be you are trying to read some files but ASPNET account has limited permissions. Please post your code so that I can have a look.

Vivek

# re: Export ASP.NET page to Word, Excel or PDF 3/9/2007 2:06 PM mitul k mehta
i am doing a project on exporting crystal report and datagrid both in word, pdf and excel format in asp.net but file save as a .aspx page please help me
my code is below

Dim attach As String = "attachment;filename =export.xls"
Response.ClearContent()
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("content-disposition", attach)
Dim str As New StringWriter
Dim htr As New HtmlTextWriter(str)
dg1.RenderControl(htr)
Response.Write(str.ToString())
'Response.Output.GetType()

# re: Export ASP.NET page to Word, Excel or PDF 3/16/2007 4:41 PM Bhuvana
Hi,
Can u tell me how to export datagrid contents to pdf file without usage of crystal reports

# re: Export ASP.NET page to Word, Excel or PDF 3/19/2007 7:02 PM Sagar shelke
hi,
///Use "application/msword" for MS Word doc files
above works for expoting to Doc
thanks.

# re: Export ASP.NET page to Word, Excel or PDF 4/2/2007 1:11 PM Om
Can anyone help me out ?
I need to export ASP.Net page in pdf.
if anyone have a sample code please sahre it with me.

# re: Export ASP.NET page to Word, Excel or PDF 4/9/2007 11:40 PM umesh
Hi Vivek,

It seems you have worked too much in transforming output to PDF, so you might resolve my problem.
My requuirement is to transform my page contents as it is to PDF file.My page may contains datagrid(s), and other server
controls. I know it is not as simple as excel or word. I visited the link http://www.codeproject.com/cs/library/giospdfnetlibrary.asp, it is good library to explore. But I want some urgent solution for this.
Can you please help me out how can I address this problem?.
If you have some source code in handy, it will be great help from your side.

Thanks

Umesh

# re: Export ASP.NET page to Word, Excel or PDF 4/10/2007 3:56 PM Vivek
Umesh,
You can use commercial PDF converters in case you want a fast solution like:

www.websupergoo.com/abcpdf-1.htm

Or some free tools like:

www.theta-software.com/freeapps.htm

www.tufat.com/s_html2ps_html2pdf.htm

Hope this helps,
Vivek



# re: Export ASP.NET page to Word, Excel or PDF 4/18/2007 12:13 PM Bonina
Hello guys!
I tryed the example and when open the dialog box, i save the file into the desktop and has like a .xls file. However when i open it and i insert a new worsheet to manipulate the file, i click the button save, it saves like a html file (creat a new folder). I have to "save as" to save like excel file. Does everyone knows why it happened?

Thank you!

# re: Export ASP.NET page to Word, Excel or PDF 4/25/2007 7:41 AM Ramesh
can anybody send vb.net coding for export gridview data in pdf format

# re: Export ASP.NET page to Word, Excel or PDF 6/11/2007 8:37 AM magicmonkey
For this solution to work, Do i need to have installed word/Excel on the server? Or it will work if client has word installed

# re: Export ASP.NET page to Word, Excel or PDF 6/12/2007 1:33 PM Vivek
You dont need word/excel on the server, but the client needs to have the same installed so that he/she can view the downloaded file.

# re: Export ASP.NET page to Word, Excel or PDF 6/19/2007 6:43 PM Matt
A good, free, open source PDF generator is iTextSharp (http://itextsharp.sourceforge.net). It has a bit of a learning curve, but it's powerful -- and Free!

# re: Export ASP.NET page to Word, Excel or PDF 6/26/2007 3:43 PM Jagdish Kotian
after successfull export i am getting such ’” charater for ', pls help

# re: Export ASP.NET page to PDF file 6/28/2007 12:11 PM Sandeep Barsaiyan
hi
can any one solve me problem i want to expoert my aspx page into pdf file which is contained server control like datagrid,lable tables etc.its urgent.plz help me.thnx

# re: Export ASP.NET page to Word, Excel or PDF 7/30/2007 9:51 AM Aswath
Hi,

I tired with the above code to export to excel , but iam not getting alignment properly.the gridlines in excel sheet are not visable.what i want to do now?but it is displaying output correctly.so plz help me

regards,
Aswath.

# re: Export ASP.NET page to Word, Excel or PDF 7/31/2007 10:42 AM Kamal Jindal
I tryed the example and when open the dialog box, i save the file into the desktop and has like a .xls file. However when i open it and i insert a new worsheet to manipulate the file, i click the button save, it saves like a html file (creat a new folder). I have to "save as" to save like excel file. Does everyone knows why it happened?

after export to excel, i am import this file. but connection string is show me that 'this file not in expected format". because it's save like web page. after this we save as this file in xls. then it' come.

please send orginal code on my email id

Thank you!

# re: Export ASP.NET page to Word, Excel or PDF 8/23/2007 12:05 PM ziad chalhoub
dear all
could u send me the code in asp.net that save the page in pdf format.
regards

# re: Export ASP.NET page to Word, Excel or PDF 9/6/2007 8:14 AM Pp
I am trying to export the griddata in word but I want to print/export them in simple table format. Table have 3 fields say A, B, C. Last field C is quite big having more than 255 characters so I want to continue printing that on next line in the same column C, not as totally new line say print from column A. Does any one have idea how format or handle the output by programming using vb.net.



# re: Export ASP.NET page to Word, Excel or PDF 9/12/2007 12:08 PM subrata
cold u send me the code in asp.net to send a mail with attachment , subject .

# re: Export ASP.NET page to Word, Excel or PDF 9/19/2007 4:28 PM phil
Gee, no matter how much you tell people they still beg you for the code to do it, even though you've already told them how to do it! I feel for you. Guess some people rely on copy paste to keep their job and don't want to actually learn how to write it for themselves :(

# re: Export ASP.NET page to Word, Excel or PDF 9/24/2007 4:18 PM farah
Hi
plz can u write this code in vb.net


best regards

# re: Export ASP.NET page to Word, Excel or PDF 9/26/2007 11:28 PM Janki
I am exporting a gridview results to excel.
gvOrganizations.AllowSorting = False
gvOrganizations.AllowPaging = False
gvOrganizations.Visible = True

Response.ContentType = "application/vnd.ms-excel"


It works fine for small number of records but if its more than 1000 it gives message Unable to read file then takes you to the VS 2005 IDE in the aspx code.
The EnableViewState in the gridview is set to false.
The error comes only on some machine.
what can be the reason?

# re: Export ASP.NET page to Word, Excel or PDF 10/1/2007 5:05 PM krishnadhar
hi your code works fine. but what if a web application has an image, this your will display every thing except the image.

# re: Export ASP.NET page to Word, Excel or PDF 10/12/2007 1:13 PM Sunitha
Very good one, It really help me a lot.

# re: Export ASP.NET page to Word, Excel or PDF 10/23/2007 6:23 PM Chai
How about exporting the image together with the gridview?
Do you know how to include the image into the xcel or word?

thanks,
Chai

# re: Export ASP.NET page to Word, Excel or PDF 10/23/2007 9:00 PM Chai
I got it.
Need a full image path instead of those src='../image/abc.gif'

need to be src='http://domain/app/image/abc.gif'

have fun,
Chai

# re: Export ASP.NET page to Word, Excel or PDF 11/5/2007 3:05 PM Rajneesh
Dear All
If u have to import any kind of data & images you can use the dll as itextsharp(dll).just read out the tutoiral to implement & use this dll.it is easy to use & i have implemented it many application.
just search itextsharp.dll on google.download full tutorial.


thanks
Rajneesh

# re: Export ASP.NET page to Word, Excel or PDF 11/19/2007 12:25 AM Amit Kumar Srivastava
how can we export whole data including images and drawings etc to word or pdf fromat.....can any one guide me.....


Thanks in advance

# re: Export ASP.NET page to Word, Excel or PDF 11/29/2007 11:43 AM prashat
hello,
This is very use full code, but it's working good when i am using datagrid but when i use only lable's that bind from databse,when when i am trying to export this lable in xls it show span tag with lable id can let me know solution for this.

# re: Export ASP.NET page to Word, Excel or PDF 11/29/2007 1:58 PM karbagamoorthy
Is there any common services available for Export data to standard formats such as Excel,PDF,Word and Xml.

Please let me know,do you know solutions.

Thanks,Karbagamoorthy

# re: Export ASP.NET page to Word, Excel or PDF 12/6/2007 10:26 AM Mohana
while exporting the data's from Database to a grid in excel format using the above code, i am getting such ’” charater for ', “,” for “ and ”. Please help me with the solution

# re: Export ASP.NET page to Word, Excel or PDF 12/10/2007 4:01 PM kavi
Can anyone help me out how to generate a report in Excel through asp.net?How to place the text in each cell,i tried with creating worksheet in VS -2005?please send a sample coding?

# re: Export ASP.NET page to Word, Excel or PDF 12/12/2007 8:54 AM Balaji
hi vivek,

im trying to open an Cognos report using the hyper link during the page load. do can i save( View) the same report as a excel sheet.

String url = @"http://CHDTEGV/Cognos8/cgi-bin/Cognos.cgi?
HyperLink1.NavigateUrl = url;

this will give me an cognos report is it possible to view the same report as Excel.

kindly provide me with an solution



# re: Export ASP.NET page to Word, Excel or PDF 12/13/2007 12:04 PM aries
hi,

I am using the example provided in http://www.codeproject.com/cs/library/giospdfnetlibrary.asp to create PDF file after retrieving the data from Microsoft Access. (in VB.net) However, i got an error message saying:

Exception Details: System.Exception: Error opening destination file

I grant permission on writing to the folder, but the error still there.

Could i get some advice about that?



# re: Export ASP.NET page to Word, Excel or PDF 12/13/2007 3:35 PM thalha
have a look on
http://asp-net-whidbey.blogspot.com/2006/04/generating-pdf-files-with-itextsharp.html

# re: Export ASP.NET page to Word, Excel or PDF 12/20/2007 3:21 PM Tarun Sood
I am exporting the asp.net page into ms word and ms office by using above code and its working but problem arises

1) during export in word, word page get distorted due to the html setting and images were not displayed in the exported doc file.

2) during export in excel, images are exported nicely but the page get distorted due to the html.

How to handle the html and Image problem?

Can somebody help me out ASAP!!

Thanks in Advance!

# re: Export ASP.NET page to Word, Excel or PDF 1/12/2008 10:51 AM Vikram
Hi Vivek,
I want to diplay formatted HTML(which retains paragraphs and bullets etc.) in gridview column.So to display the same i have used TextArea in Gridview.
But now i want to export that grid to word which renders textarea with control as it is to word(with borders and scroll).
So,please suggest a HTML control which renders formatted HTML after exporting to word.

Cheers,
Vikram

# re: Export ASP.NET page to Word, Excel or PDF 1/25/2008 4:16 PM vipin
Hi to all i hava a code that works fine and with is i can easily make pdf files

using System.IO;
using System.Diagnostics;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;

Document myDocument;
myDocument = new Document(PageSize.A4.Rotate());
PdfWriter.GetInstance(myDocument, new FileStream("c:\\zz.pdf", FileMode.Create));
myDocument.Open();
// myDocument.Add(new Paragraph(tmp));

//myDocument.Close();


Enjoy !!

I have devoted one complete day in searching of some code for pdf.

You have to add refrence of iTextSharp..

# re: Export ASP.NET page to Word, Excel or PDF 1/28/2008 3:26 PM sambarta
Hi Vivek,

I am using the following piece of code to export the gridview to excel.
Response.Clear();

Response.AddHeader("content-disposition", "attachment; filename=FileName.pdf");

Response.Charset = "";

// If you want the option to open the Excel file without saving than

// comment out the line below

//Response.Cache.SetCacheability(HttpCacheability.NoCache);

Response.ContentType = "application/.pdf";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();

System.Web.UI.HtmlTextWriter htmlWrite =
new HtmlTextWriter(stringWrite);

GridViewtest.RenderControl(htmlWrite);

Response.Write(stringWrite.ToString());

Response.End();

But this is giving me some error"Adobe reader could not open the file filename.pdf"... please help. I cannot use any third party component for the export

# re: Export ASP.NET page to Word, Excel or PDF 1/28/2008 3:40 PM Vivek
Response.ContentType = "application/.pdf";

You are exporting to PDF, and not excel.

also, as specified in my post, exporting to PDF is not possible without using an external component!

Cheers
Vivek

# re: Export ASP.NET page to Word, Excel or PDF 2/1/2008 9:34 PM ettore
HTML export to Excel doesn't allow any control on output. Moreover since it makes a large output, it's so much slow that it becomes unusable with a only few hundred of records.

If you need a real Export to Excel and the capability to define Excel column Types you need a tool like this: http://www.gridviewtoexcel.com

It allows you even to totalize numeric columns. and can zip and send the export via emal.

Cheers

# re: Export ASP.NET page to Word, Excel or PDF 2/5/2008 2:29 PM Pradeep
hi,

i am geting the following error

"System.InvalidOperationException: RegisterForEventValidation can only be called during Render();"


# re: Export ASP.NET page to Word, Excel or PDF 2/14/2008 4:34 PM nive
Hi
how to import image into excel from asp.net?
any help would be appreciated.

Thanks
Regards


# re: Export ASP.NET page to Word, Excel or PDF 2/20/2008 6:23 PM sunita
I exported the datagrid to ms-excel,word and pdf but in those exported file there is no heading that what's type of data reside in it.
I want to know how to provide heading or say title to the document

Please give me some suggestion so that i can do it.

Thanks

# re: Export ASP.NET page to Word, Excel or PDF 2/20/2008 6:46 PM prashu
dear all,


would u please tell me how to export crystal reports to excel when we click a button using c# in asp.net
thank u


# re: Export ASP.NET page to Word, Excel or PDF 3/1/2008 4:05 AM soumya
I bought the dbautotrack pdf writer to export datagrid to PDF format.Can some one help me in suggesting me some sample code for exporting datagrid to PDF

# Export ASP.NET page to powerpoint presentation 3/4/2008 9:22 AM senthil
how to export to datagrid to powerpoint presentation

# re: Export ASP.NET page to Word, Excel or PDF 3/26/2008 7:59 PM Lewis B
Does anyone know how to export an ASP.Net grid to Excel and have the Excel file READ ONLY (so the user cannot save but can only Save As?

# re: Export ASP.NET page to Word, Excel or PDF 4/1/2008 11:52 AM vishal
when i am using iTextSharp.dll to generate pdf on web-server. it is showing below error.

System.Security.SecurityException: That assembly does not allow partially trusted callers.

Please any one solve this problem and reply me..


# re: Export ASP.NET page to Word, Excel or PDF 4/1/2008 12:18 PM Ajith S Kulgod
This Article Was Very Helpfull.Thank You

# re: Export ASP.NET page to Word, Excel or PDF 4/1/2008 9:31 PM carolina
Hola a todos

Necesito exportar desde ASPX a pdf, o sea no de C# ni de J# y tampoco de vb, sino q desde aspx, existe alguna forma de hacerlo pq sólo he visto de las otras formas pero nada en ASPX?

# re: Export ASP.NET page to Word, Excel or PDF 4/8/2008 3:07 AM somesh
Response.ContentType = "application/vnd.ms-excel";

Export to Excel is not working when user sysetem is install office 2007.

Please do suggest me, how to reslove this.

# re: Export ASP.NET page to Word, Excel or PDF 4/15/2008 12:45 AM Joeller
On 2/27/2007 Karthik reported "Hi ,

I was not able to view the generated excel file . Following error occurred "Unable to read the file" . Let me know if u have any answers .... "

ON 3/1/2007 at 410:11 AM you replied
"Karthik,

May be you are trying to read some files but ASPNET account has limited permissions. Please post your code so that I can have a look.

Vivek "

However there is no sign that either was done.

I am getting the same issue from one page but the other page in a different folder on the same website does not cause that error. Both folders have exactly the same permissions.

The code for each page is
"
Response.ClearHeaders()
Response.ClearContent()

If sExportType = "Excel" Then
'This will cause the page when loaded to open a dialog box asking the user to decide
'whether to open the page in excel or save the page as an excel file.
Response.AddHeader("content-type", "application/vnd.ms-excel")
Response.AddHeader("content-disposition", "attachment;filename=""Report.xls""")
"


# re: Export ASP.NET page to Word, Excel or PDF 4/15/2008 2:27 AM Joeller
I was able to resolve the above by entering the line in the non-working page " Me.EnableViewState = False". However now the excel file that opens cuts off the first 290 rows of the resultset. I have utilized several different methods of rendering the excel page from the code above to added the lines below to the sub procedure.

" Response.Charset = String.Empty

Dim myTextWriter As New System.IO.StringWriter()
Dim myHtmlTextWriter As New System.Web.UI.HtmlTextWriter(myTextWriter)

'Get the HTML for the control

Me.dgReport.RenderControl(myHtmlTextWriter)


Response.Write(myTextWriter.ToString())
Response.End() "
However the end result is the same. When I change the original two lines to
Response.AddHeader("content-type", "application/text/HTML")
Response.AddHeader("content-disposition", "attachment;filename=""Report.htm""") The page opens with all the needed data presented. By the same token when I open the same page as a pdf using ASPPDF, It also lists all of the specified rows. Only in Excel is the resultset truncated. It seems illogical.


# re: Export ASP.NET page to Word, Excel or PDF 4/24/2008 10:58 AM Murtaza
Hi!

I am exporting gridview to excel.. I want to know how can i insert a new line in the excel sheet.

Thanx,

# re: Export ASP.NET page to Word, Excel or PDF 5/5/2008 11:49 AM giri
hi ,
I want code for export data from datagrid to pdf file .can any body reply for this and please tell me which external tools i have to use for this pls share me those links also.

# re: Export ASP.NET page to Word, Excel or PDF 5/9/2008 12:05 AM Brian
I am using Response.ContentType = "application/msword" in an asp.net application and it works fine with Word 2000 but if a user has Word 2003 or Word 2007 installed it does not work. I have Word 2000 and 2003 installed on my machine and it works. Anybody know what I can do to make this work on machines with Word 2003 or 2007?

Brian


# re: Export ASP.NET page to Word, Excel or PDF 5/12/2008 11:54 AM Ajit Kumar Thakur
Hi i Have tried the same but after saving it ,file is unable to open in acrobat reader.

# re: Export ASP.NET page to Word, Excel or PDF 5/16/2008 3:44 PM wsg
Hi,
U told that without using third party we can't export data to pdf. I used coding, the pdf is opened with "could not open sample.pdf"
How to Resolve this?

# re: Export ASP.NET page to Word, Excel or PDF 5/27/2008 10:19 AM Parmanandkumar jaiswal
Hi,
I have a problem pls give me solution
I m having a gridView in webPage which agin contain a grid in its fifth cell. and this inner grid conatins Image control in its 3rd cell. Now I want export this Complete GridView to Excel/word..but problem is All data is coming right but images are not coming for showing the image i have to carry that image folder along with it. Is there any solution so that Exsported word or excel file Embed the images..

if you have any solution pls mail it on prem_jaiswal8183@yahoo.co.in

Thanks for reading the problem.

# re: Export ASP.NET page to Word, Excel or PDF but disable Cut,Copy and Paste Feature 6/3/2008 7:30 PM Mukesh Chourasia
i want to export to excel but no buddy can cut,copy or paste the content using crtl+c,Ctrl+v or using menu.
plz help me

# re: Export ASP.NET page to Word, Excel or PDF 6/5/2008 11:18 AM Ramya
Hi,
Can anyone please tell me how to export a datagrid to excel with the existing styles and formats in datagrid.

# re: Export ASP.NET page to Word, Excel or PDF 6/5/2008 4:44 PM Ashish
I have used same code...where i am getting the content of a <div>. I am getting whole tags displayed in the exported document...please help!!!!!!!!!

ashish

# re: Export ASP.NET page to Word, Excel or PDF 6/7/2008 12:23 AM Burrell
the only way I could get my datagrid to excel was to surround it with table tags.
<form>
<table id="gridtable">
<tr>
<td>
<datagrid>
</td>
</tr>
</table>
</form>

then in button click event

Dim attach As String = "attachment;filename =export.xls"
Response.Clear()
Response.Buffer = True '
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = ""
Response.AddHeader("content-disposition", attach)
Dim strWriter As New StringWriter()
Dim htmlWriter As New HtmlTextWriter(strWriter)
Me.gridtable.RenderControl(htmlWriter)
Response.Write(strWriter.ToString())
Response.End()

works great for me.

# re: Export ASP.NET page to Word, Excel or PDF 6/11/2008 10:21 AM Liana
need help...
i wanna export my data to word with selection by check box at data grid that can save in word one by one with my selection. what must i do about that?

# re: Export ASP.NET page to Word, Excel or PDF 7/11/2008 2:54 PM sachin
Hi,
I want to access the word file in read only foramt using Asp.net+C# so if any body wants to modify data so it should not edit that data
so it must in read only format
for e.g If i'm exporting payslip it should not edit by other person

# re: Export ASP.NET page to Word, Excel or PDF 7/30/2008 9:38 AM kiran
Export to Excel and CSV works good by just changing the content type of the Response Object but converting to Gridview to PDF I required plz if any one knows reply Its very urgent

# how can i insert file in the box attachment in vb.net 8/18/2008 6:42 PM motaz
please help meeeeeeeee how can i inser the file from the folder auotomaticlly in attachment box

thx

# how can i insert file in the box attachment in vb.net 8/18/2008 6:43 PM motaz
please help meeeeeeeee how can i insert
the file from the folder auotomaticlly in attachment box

thx

# re: Export ASP.NET page to Word, Excel or PDF 9/11/2008 11:11 PM rs
I tried this and everything works fine but on my page there is a table that has all text and images. If the text size goes beyond( the data) certain size then it doesn't show the rest of the page. Looks like Word renders upto a certain size and then the rest of the html is not rendered at all. Anyone come across this problem? Any solutions?
Thanks

# re: Export ASP.NET page to Word, Excel or PDF 9/16/2008 10:05 AM Soorya
I tried this code.but image is not displaying in the converted WORD file.pls give me a solution ASAP

# re: Export ASP.NET page to Word, Excel or PDF 9/19/2008 4:37 PM akin
Hi ,
I want to do aspx page to pdf and i used to itextsharp component.In my aspx page ı ıse formview and get data from database and i want to this page to pdf file .But i can not get it.Please help me..

# re: Export ASP.NET page to Word, Excel or PDF 10/9/2008 5:40 PM Vijay
hi,
using above code
i am geting the following error
i just want to convert simple aspx page with gridview into pdf:



"System.InvalidOperationException: RegisterForEventValidation can only be called during Render();"


pls help me fast m in hurry pls pls

# re: Export ASP.NET page to Word, Excel or PDF 10/16/2008 5:38 PM Mustufa sathaliya
try this code to copy gridview to pdf file. Its working code !

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim connect As String = "Data Source=com20;Initial Catalog=Test;Integrated Security=True"
Dim con As New SqlConnection(connect)
con.Open()
Dim str As String = "SELECT * from login"
Dim cmd As New SqlCommand(str, con)
Dim rd As SqlDataReader = cmd.ExecuteReader
gridview1.DataSource = rd
gridview1.DataBind()

End Sub


Protected Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
form1.Controls.Clear()
form1.Controls.Add(gridview1)
Dim sw As New System.Text.StringBuilder()
Dim htw As New HtmlTextWriter(New System.IO.StringWriter(sw))
form1.RenderControl(htw)
Dim html As String = "<html><body><form runat=""server"">" + sw.ToString() + "</form></body></html>"
Response.Clear()
Response.ContentType = "application/pdf"
Dim document As New iTextSharp.text.Document(PageSize.A4, 80, 50, 30, 65)
Dim writer As iTextSharp.text.pdf.PdfWriter = PdfWriter.GetInstance(document, Response.OutputStream)
document.Open()
Dim tempFile As String = Path.GetTempFileName()
Using tempwriter As New IO.StreamWriter(tempFile, False)
tempwriter.Write(html)
End Using
HtmlParser.Parse(document, tempFile)
document.Close()
writer.Close()
File.Delete(tempFile)
writer = Nothing
document = Nothing
Response.[End]()
End Sub


# re: Export ASP.NET page to Word, Excel or PDF 10/20/2008 2:32 PM jhatzics
Thr HtmlParser.Parse() function is yours? Or you add it from a library?

# re: Export ASP.NET page to Word, Excel or PDF 11/11/2008 9:14 AM Tera
Helpful link. There is a .net control that takes a datasource and converts it to a PDF.
www.datatabletopdf.com

# re: Export ASP.NET page to Word, Excel or PDF 11/19/2008 10:17 AM piy
i want to add image and display it in to pdf

# re: Export ASP.NET page to Word, Excel or PDF 12/2/2008 5:22 PM MVP
Someone has copied your stuff

http://dotnettutorial.wordpress.com/2008/04/17/export-aspnet-page-content-to-word-excel-or-pdf/

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 4 and 1 and type the answer here: