C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Add image to word in C#


Posted Date: 28 Oct 2009    Resource Type: Code Snippets    Category: C# Syntax
Author: Nikhil GaurMember Level: Diamond    
Rating: 1 out of 5Points: 10



Hi everyone,
If you want to add an image to word document automatically via c# code use my code. i used with Microsoft.Office.Interop.Word.Document object to open the word document, and then i used the Shapes.AddPicture method for inserting the image into the documents.

I didn't use the InlineShapes.AddPicture method because, these method doesn't support layers etc.

here is my code:

object FileName = filesCollection.ToString();
object saveFileName = FileName;
object vk_read_only = false;
object vk_visibile = true;
object vk_false = false;
object vk_true = true;
object vk_dynamic = 2;
object vk_missing = System.Reflection.Missing.Value;
object LinkToFile = true;
object myRange = System.Reflection.Missing.Value;
object vk_format = Microsoft.Office.Interop.Word.WdOpenFormat.wdOpenFormatDocument;
object Left = 1;
object Top = 1;
object Width = 498;
object Height = 89;

oWord.Visible = true;
oWord.Activate();

Microsoft.Office.Interop.Word.Document doc = oWord.Documents.Open(ref FileName, ref vk_false, ref vk_read_only,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_visibile, ref vk_true, ref vk_missing, ref vk_missing, ref vk_missing);
doc.Shapes.AddPicture(LogoPath, ref LinkToFile, ref saveWithObject, ref Left, ref Top, ref Width, ref Height, ref vk_missing);
doc.SaveAs(ref FileName, ref vk_format, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing, ref vk_missing,
ref vk_missing, ref vk_missing, ref vk_missing);
doc.Close(ref SaveChanges, ref OriginalFormat, ref saveWithObject);


For more details, visit http://niksgaur.blogspot.com/2009/06/add-image-to-word-document-using-c-code.html



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Word  .  Shapes.AddPicture  .  Microsoft.Office.Interop.Word.Document  .  Image  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Get the selected multiple items from the listbox using c# windows application
Previous Resource: Email validation for TextBox control in c#.net windows application
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use