c# - Generate Outlook Signature with Open XML -


i have c# application uses wordinterop create outlook signature based off form input.

i want deploy application web app , have read online not use wordinterop on server type of application. reason converting open xml.

i can create docx file basic formatting signature, how can instead create outlook signature required htm, rtf , txt files?

alternatively, how take docx output , convert necessary htm, rtf , txt file types?

the code using create file followed style definitions , actual content of signature

using (wordprocessingdocument mydoc =                wordprocessingdocument.create("c:\\users\\exampleuser\\appdata\\roaming\\microsoft\\signatures\\emailsignature.rtf",                              wordprocessingdocumenttype.document))         { 

my thought need change wordprocessingdocument or wordprocessingdocumenttype.document, appreciated

edit here full logic can test locally (note step after getting base functionality consolidate styling code)

public actionresult writesignature_openxml()         {             // create wordprocessing document.              using (wordprocessingdocument mydoc =                    wordprocessingdocument.create("c:\\users\\testuser\\appdata\\roaming\\microsoft\\signatures\\emailsignature.docx",                                  wordprocessingdocumenttype.document))             {                 // add new main document part.                  maindocumentpart mainpart = mydoc.addmaindocumentpart();                 styledefinitionspart stylepart = mainpart.addnewpart<styledefinitionspart>();                  //create document tree simple document.                  mainpart.document = new document();                 //create body (this element contains                 //other elements want include                  body body = new body();                   // set properties moving message style                 runproperties rpr = new runproperties();                 color color = new color() { val = messagecolor };                 runfonts rfont = new runfonts();                 bold signatureweight = new bold();                 fontsize signaturefontsize = new fontsize() { val = "20" };                 basedon signaturebase = new basedon() { val = "heading1" };                 nextparagraphstyle signatureparagraphstyle = new nextparagraphstyle() { val = "normal" };                 rfont.ascii = "century gothic";                 rpr.append(color);                 rpr.append(rfont);                 rpr.append(signatureweight); // bold                 rpr.append(signaturefontsize);                 //create moving message style                 style movemessagestyle = new style();                 movemessagestyle.styleid = "movingmessagestyle"; //this id of style                 movemessagestyle.append(new name() { val = "movingmessagestyle" }); //this name                 movemessagestyle.append(signaturebase); // our style based on normal style                 // next paragraph normal type                 movemessagestyle.append(signatureparagraphstyle);                 movemessagestyle.append(rpr);//we adding properties defined                 // have add style have created stylepart                 stylepart.styles = new styles();                 stylepart.styles.append(movemessagestyle);                 stylepart.styles.save(); // save style part                  // set properties boldblue signature text style                 runproperties boldblue_rpr = new runproperties();                 color signature_colorblue = new color() { val = myblue };                 runfonts boldbluefont = new runfonts();                 bold signatureweight2 = new bold();                 fontsize signaturefontsize2 = new fontsize() { val = "20" };                 basedon signaturebase2 = new basedon() { val = "heading1" };                 nextparagraphstyle signatureparagraphstyle2 = new nextparagraphstyle() { val = "normal" };                 boldblue_rpr.append(signature_colorblue);                 boldblue_rpr.append(boldbluefont);                 boldblue_rpr.append(signatureweight2); // bold                 boldblue_rpr.append(signaturefontsize2);                 //create moving message style                 style signatureboldblue = new style();                 signatureboldblue.styleid = "boldbluestyle"; //this id of style                 signatureboldblue.append(new name() { val = "boldbluestyle" }); //this name                 signatureboldblue.append(signaturebase2); // our style based on normal style                 // next paragraph normal type                 signatureboldblue.append(signatureparagraphstyle2);                 signatureboldblue.append(boldblue_rpr);//we adding properties defined                 // have add style have created stylepart                 stylepart.styles.append(signatureboldblue);                 stylepart.styles.save(); // save style part                  // set properties thinblue style                 runproperties thinblue_rpr = new runproperties();                 color thinblue_color = new color() { val = myblue };                 runfonts thinbluefont = new runfonts();                 bold signatureweight3 = new bold();                 fontsize signaturefontsize3 = new fontsize() { val = "20" };                 basedon signaturebase3 = new basedon() { val = "heading1" };                 nextparagraphstyle signatureparagraphstyle3 = new nextparagraphstyle() { val = "normal" };                 thinblue_rpr.append(thinblue_color);                 thinblue_rpr.append(thinbluefont);                 thinblue_rpr.append(signaturefontsize3);                 //create moving message style                 style thinbluestyle = new style();                 thinbluestyle.styleid = "thinbluestyle"; //this id of style                 thinbluestyle.append(new name() { val = "thinbluestyle" }); //this name                 thinbluestyle.append(signaturebase3); // our style based on normal style                 // next paragraph normal type                 thinbluestyle.append(signatureparagraphstyle3);                 thinbluestyle.append(thinblue_rpr);//we adding properties defined                 // have add style have created stylepart                 stylepart.styles.append(thinbluestyle);                 stylepart.styles.save(); // save style part                   //generate message text style                 paragraph heading = new paragraph();                 run heading_run = new run();                 text heading_text = new text(movingmessage);                 paragraphproperties heading_ppr = new paragraphproperties();                 // set style                 heading_ppr.paragraphstyleid = new paragraphstyleid() { val = "movingmessagestyle" };                 heading.append(heading_ppr);                 heading_run.append(heading_text);                 heading.append(heading_run);                 body.append(heading);                  //generate employeename text style                 paragraph empname = new paragraph();                 run empname_run = new run();                 text empname_text = new text(employeename.toupper());                 paragraphproperties empname_ppr = new paragraphproperties();                 // set style                 empname_ppr.paragraphstyleid = new paragraphstyleid() { val = "boldbluestyle" };                 empname.append(empname_ppr);                 empname_run.append(empname_text);                 empname.append(empname_run);                 body.append(empname);                  paragraph title_company = new paragraph();                 run title_company_run = new run();                 text emptitle = new text(employeetitle);                 text empcompany = new text(employeecompany);                 paragraphproperties title_company_ppr = new paragraphproperties();                 // set style                 title_company_ppr.paragraphstyleid = new paragraphstyleid() { val = "thinbluestyle" };                 title_company.append(title_company_ppr);                 title_company_run.append(emptitle);                 title_company_run.append(empcompany);                 title_company.append(title_company_run);                 body.append(title_company);                     mainpart.document.append(body);                 mainpart.document.save();             }              return view();         } 


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -