We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Simple question

So, i want to save some text to a Document. I used code from this sample provided by the website:

// A new document is created.
WordDocument document = new WordDocument();

// Add a new section to the document.
IWSection section = document.AddSection();

// Adding a new paragraph to the section.
IWParagraph paragraph = section.AddParagraph();

// Insert Text into the paragraph
paragraph.AppendText("Hello World!");

// Streaming the document to the client browser.
if (this.CheckBox1.Checked)
document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.InBrowser);
else
document.Save("Sample.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment);

Now, the document is saved but when i open it it gives me an error. Something about the file being corrupt. Can anyone help me on this and guide me how to save some simple text to a document.

And another question if i may. How to apply font size and bold to a paragraph since from the example above, it seems that i could only apply one type of 'FormatType'.

Thanks and regards.


6 Replies

AD Administrator Syncfusion Team August 13, 2008 06:46 AM UTC

Another question, i am now saving to a txt since doc is not working. Apart from the data given, it is also saving the html code from the browser, can anyone help me please.

Thanks



BP Bhuvaneswari P Syncfusion Team August 13, 2008 12:52 PM UTC

Hi Owen,

Thank you for your interest in Syncfusion products.

1. File open issue :
I am afraid that I am not able to reproduce the issue. I am able to open the document without any file crash. Please provide the below details to reproduce the issue in our end
1. OS details
2. Essential Studio version
3. MS Office version
4. Browser version
This would help us to reproduce and investigate more on this.

2. Text Format

You can apply various formats to single text by using the TextRange CharacterFormart property. Please refer the below code snippet to do so:

WTextRange range= paragraph.AppendText("Hello World!");
range.CharacterFormat.Bold = true;
range.CharacterFormat.FontSize = 10;
range.CharacterFormat.TextBackgroundColor = Color.Green;

Please let me know if you have any other questions.

Best Regards,
Bhuvana




AD Administrator Syncfusion Team August 14, 2008 05:10 AM UTC

These are the details you asked for:

1. OS details
Windows XP Professional Edition

2. Essential Studio version
5.1.1.0

3. MS Office version
Office 2003

4. Browser version
IE7

As i said before the document created was always created corrupted, but when i saved it to text, the data is shown but underneath the data given the website's HTML code is also printed in the file.

Below is the code i am using to save a document.

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO.Utilities;
using Syncfusion.DocIO.IO;
using Syncfusion.DocIO.ReaderWriter;

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
IWordDocument doc = new WordDocument();
IWSection sec = doc.AddSection();
IWParagraph par = sec.AddParagraph();

par.AppendText("HAQQ ALLA GHAMEL DISPLAY!!");
doc.Save("BillingReportChanges.doc", FormatType.Doc, Response, HttpContentDisposition.Attachment);
}
}




BP Bhuvaneswari P Syncfusion Team August 14, 2008 01:08 PM UTC

Hi Owen,

Thanks for the system details.

I am afraid that still I am not able to reproduce the issue in the given environment. It works fine. Could you please open a new direct – trac incident with subject line as Forum 75871 -Simple question So that it would be possible for us to provide more details regarding this issue.

Best Regards,
Bhuvana




AD Administrator Syncfusion Team August 14, 2008 03:03 PM UTC

Thanks, i will open one later on since i'm quite in a hurry now. But i think the problem with the DOC is the fact that it has some characters that mess with the doc, since it seems that apart from the data given it also saves the website's source code. So i beleive the issue is related to that fact. If you have any suggestions or ideas why it would also save the source code please let me know.

>Hi Owen,

Thanks for the system details.

I am afraid that still I am not able to reproduce the issue in the given environment. It works fine. Could you please open a new direct – trac incident with subject line as Forum 75871 -Simple question So that it would be possible for us to provide more details regarding this issue.

Best Regards,
Bhuvana






BP Bhuvaneswari P Syncfusion Team August 18, 2008 05:45 AM UTC

Hi Owen,

Thanks for the update.

I am able to see the issue that you have mentioned "while opening the text file in the browser it show some unwanted text”, but the issue has been fixed in the latest versions. We recommend you to upgrade our latest version.

You can download the latest version from the below link:

http://www.syncfusion.com/downloads/latestversion/default.aspx


Unlock key:
If your Essential Studio license is current, you will be able to obtain the key to install this version from your account in DirectTrac. Otherwise, please contact your Syncfusion Sales Representative or e-mail salessupport@syncfusion.com.

Please let me know if you have any other concerns.

Best Regards,
Bhuvana



Loader.
Live Chat Icon For mobile
Up arrow icon