Free Support Forum - aspose.com

Advice needed on .net and Aspose Integration

Hello,

I would like to integrate aspose with .net (C#) to see how exactly I can convert the .dot files to .doc file.and I am doing this for the very first time, I would really appreciate if you can help me to understand how exactly this can be done step by step.

Thanks,

NiK

Hi

Thanks for your request. You can use the following simple code to achieve this:

Document doc = new Document(@"in.dot");

doc.Save(@"out.doc");

Best regards,

Thanks for your Mail, that indeed helped me !

I have requirement like reading a word doc and replace all the book marks in the document with the appropirate words, i am giving.Can i do this? Is there any mechanism to do this in aspose?

Hi

Thanks for your request. Please see the following link to learn how to work with bookmarks in Aspose.Words:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/working-with-bookmarks.html

Please see the following code example:

Document doc = new Document("Bookmark.doc");

// Use the indexer of the Bookmarks collection to obtain the desired bookmark.

Bookmark bookmark = doc.Range.Bookmarks["MyBookmark"];

// Get the name and text of the bookmark.

string name = bookmark.Name;

string text = bookmark.Text;

// Set the text of the bookmark.

bookmark.Text = "This is a new bookmarked text.";

Best regards,

I just want to read a word template and create another copy of it with mail merge feature.The data to replace is Name and Address the rest of the things in the template should remains the same. Can you please tell me how to do this ?

Hello

Thanks for your request. I think the best way to fill the document with data is using Mail Merge feature. Please follow this link to learn more:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/simple-mail-merge-explained.html

Best regards,

Hi,

I am able to replace the bookmarks with my own texts but, I can still see the old bookmarks. how can i completely remove the old bookmarks and replace it with my words?

Hello

Thank you for additional information. Could you please clarify, if you would like to remove all bookmarks from the document, you should use the following code:

Document.Range.Bookmarks.Clear();

Or if you just want to clear bookmark text, you should use the code like this:

doc.Range.Bookmarks["mybk"].Text = "";

Best regards,

thanks for your answer and it worked!!

Is there any way we can convert the dot file to doc or pdf on the fly. I mean with out storing physically.

Hello

Thanks for your request. Please see the following link to learn how to achieve what you need:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.document.save_overload_4.html

Best regards,

Thanks for your answer!

Document doc = new Document(MyDir + "Document.doc");

MemoryStream dstStream = new MemoryStream();
doc.Save(dstStream, SaveFormat.Docx);

// Rewind the stream position back to zero so it is ready for next reader.
dstStream.Position = 0;

In this code, whats is the MyDir words stands for, where we can declare that? and where exactly these docx file getting saved? how I can tarnsfer this file over a network using wcf service?

Ok.. I understood MyDir is for the physicall path. ok.. another doubt i have.

I have saved the document in to memory stream and now how can i retrieve the document?

Hi

Thanks for your request. Please see the following link to learn how to open an existing document from a stream:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.documentconstructor4.html

Best regards,

It would be great if you can help me in this..

I have a requirement like accepts a template (.dot or .docx with bookmarks) and using the data received from other application replace all the BookMarks with the same name in the template. any Idea, or any suggestion. Pls its urgent.

Hi

Thanks for your request. Please see the following link to learn how to work with bookmarks in Aspose.Words:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/working-with-bookmarks.html

Please see the following code example:

Document doc = new Document("Bookmark.dot"); // or it can be docx

// Use the name of the Bookmark to obtain the desired bookmark.

Bookmark bookmark = doc.Range.Bookmarks["MyBookmark"];

// Set the text of the bookmark.

bookmark.Text = "This is a new bookmarked text."; // The data from your application

Best regards,

Yes, Its true for manual work..

So , what is that if i need to replace the bookmarks of the template depend on the bookmark name i am geting as input to my system.( I am talking about dynamic situation, where this assigning manually for bookmark wont work)

Hi

Thank you for additional information. In your case you can loop through your datatable (or what you have as input), find Bookmark by name in the document and insert the appropriate content. I do not see any problems here.

Best regards,

I would like to know, how it can be done dynamically, the above sample you have given is good for a manual one , like manully asigning the bookmarks name and text and all, but when we need to do something dynamically .. Consider I am getting a xml doc as input from system called "A" with Bookmark name and respective values, that document i should compare with the docx or dot template that i am recieving from other system called "B", Here i should replace the bookMarks in template what i am recieving from "B" with the one i got from "A" dynamically.

All Ideas or thoughts are welcome.

Hi

Thanks for your inquiry. But I also do not see any problem here. You should just get name of the bookmark from your data source, check whether this bookmark is present in the document and if so insert text into the bookmark. Here is very simple code that demonstrates how you can achieve this:

// Open XML that contains bookmark names and values.

XmlDocument xml = new XmlDocument();

xml.Load(@"Test001\data.xml");

// Open template document.

Document doc = new Document(@"Test001\in.doc");

// Get collection of 'bookmark' nodes in the xml

// and insert values into the appropriate bookmarks in the document

XmlNodeList bookmarkNodes = xml.GetElementsByTagName("bookmark");

foreach (XmlNode bookmarkNode in bookmarkNodes)

{

// Get bookmark from the document.

Bookmark bookmark = doc.Range.Bookmarks[bookmarkNode.Attributes["name"].Value];

// if bookmarks exists set its text.

if (bookmark != null)

bookmark.Text = bookmarkNode.Attributes["value"].Value;

}

// Save output.

doc.Save(@"Test001\out.doc");

Here is XML I used for testing:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>

<bookmarks>

<bookmark name="firstBookmark" value="This is value of the first bookmark" />

<bookmark name="secondBookmark" value="This is value of the second bookmark" />

<bookmark name="thirdBookmark" value="bla bla bla" />

</bookmarks>

Best regards,

Thanks... That worked for me...

I really appreciate your time and effort for this.Thanks one more time.

I have successfully done those steps,but now when i am converting the document to pdf format, i am seeing some of the logos in the template it not appearing as correctly in pdf. I mean the alignment of the logos.

doc.Save("C:\\Documents and Settings\\Mycomputer\\Desktop\\docs\\Template Files\\converted\\SS_File.docx",SaveFormat.Docx);

doc.Save("C:\\Documents and Settings\\Mycomputer\\Desktop\\docs\\Template Files\\converted\\SS_File.pdf",SaveFormat.Pdf);

This is the code, I have used. pls help me.