I have an application where I create MS Word object and then fill it with some data and tables
after that I have the choice either to save the word file or to send the contents as an email without saving them
so the problem i want to get all the contents of the document (pictures, tables, ...etc) and insert them into an email body
here is the code that creates the contents
Globals.gallery.MoveFirst(); //This is a recordset to a table
string[] picNames = new string[Globals.gallery.RecordCount];
Image[] picImages = new Image[Globals.gallery.RecordCount];
// get an array of images to be added to a table
for (int i = 0; i < Globals.gallery.RecordCount; i++)
{
picNames[i] = Globals.gallery.Fields["Name"].Value.ToString();
picImages[i] = Image.FromFile(Globals.gallery.Fields["Path"].Value.ToString());
Globals.gallery.MoveNext();
}
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
object missing = System.Reflection.Missing.Value;
object isVisible = true;
// Create a new Document, by calling the Add function in the Documents collection
Microsoft.Office.Interop.Word.Document aDoc = wordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
// need to see the created document, so make it visible
wordApp.Visible = true;
aDoc.Activate();
// Global Constant enumerations are members of Word and can be assigned to properties
// Set alignment to the center of the document
//wordApp.Activedocument.PageSetup.TopMargin = (float)20;
//wordApp.Activedocument.PageSetup.BottomMargin = (float)10;
// Set up the header information.
object start = 0;
object end = 0;
Microsoft.Office.Interop.Word.Range rng = wordApp.Activedocument.Range(ref start, ref end);
rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
rng.InsertBefore("Gallery");
rng.Font.Name = "Arial";
rng.Font.Size = 30;
rng.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlue;
rng.InsertParagraphAfter();
rng.SetRange(rng.End, rng.End);
rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
rng.InsertBefore(Globals.currentCust + " Favorites List");
rng.Font.Name = "Ancestory SF";
rng.Font.Size = 20;
rng.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorDarkGreen;
rng.InsertParagraphAfter();
rng.SetRange(rng.End, rng.End);
rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
rng.InsertBefore(Globals.currentCust + " Notes:");
rng.Font.Name = "Ancestory SF";
rng.Font.Size = 15;
rng.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBrown;
rng.InsertParagraphAfter();
rng.SetRange(rng.End, rng.End);
int startObj = 0;
Globals.users.Find("UID=" + Globals.id, 0, ADODB.SearchDirectionEnum.adSearchForward, startObj);
rng.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
rng.InsertBefore(Globals.users.Fields["UNotes"].Value.ToString());
rng.Font.Name = "Arial Black";
rng.Font.Size = 10;
rng.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBlack;
rng.InsertParagraphAfter();
rng.SetRange(rng.End, rng.End);
Object defaultTablebehavior = Type.Missing;
Object autoFitbehavior = Type.Missing;
wordApp.Activedocument.Tables.Add(rng, 1, 2,
ref defaultTablebehavior, ref autoFitbehavior);
Microsoft.Office.Interop.Word.Table tbl = wordApp.Activedocument.Tables[1];
tbl.Range.Font.Size = 8;
tbl.Range.Font.Name = "Verdana";
Object style = "Colorful Grid - Accent 4";
tbl.set_Style(ref style);
tbl.ApplyStyleFirstColumn = false;
tbl.ApplyStyleLastColumn = false;
tbl.ApplyStyleLastRow = false;
// Insert header text and format the columns.
tbl.Cell(1, 1).Range.Text = "Picture";
Microsoft.Office.Interop.Word.Range rngCell;
rngCell = tbl.Cell(1, 2).Range;
rngCell.Text = "Name";
rngCell.ParagraphFormat.Alignment =
Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
// Fill the table with data.
Object beforeRow = Type.Missing;
for (int i = 0; i < Globals.gallery.RecordCount; i++)
{
tbl.Rows.Add(ref beforeRow);
Bitmap newBit = new Bitmap(picImages[i], new Size(100, 100));
newBit.Save("temp.jpg");
string path = Application.ExecutablePath.Remove(Application.ExecutablePath.LastIndexOf("\\")) + "\\temp.jpg";
rngCell = tbl.Cell(i + 2, 1).Range;
object obj = (object)rngCell;
rngCell.InlineShapes.AddPicture(path, ref missing, ref missing, ref obj);
tbl.Cell(i + 2, 2).Range.Text = picNames[i];
}
till this line I didn't save the document
and I want to take these contents with the same format and copy them to the email body
MailMessage mail = new MailMessage();
mail.From = new MailAddress("ahmedn32004@yahoo.com", "Ahmedn1");
mail.To.Add(new MailAddress("ahmedn32004@yahoo.com", "Ahmedn1 Receiver"));
mail.Subject = "Test";
any ideas?

New Topic/Question
Reply




MultiQuote





|