Cierre de aplicación WORD
Publicado por Sabina Martínez (3 intervenciones) el 31/08/2011 17:03:47
Hola a Todos!!! 
Tengo na palicación, la cual genera un archivo en WORD y le incrusta una imagen, al momento de correrlo desde mi Visual Estudio, todo bien, me genera el documento sin mayor problema, pero al momento de publicarlo en mi servidor de IIS ya no me cierra la aplicación y por ende el archivo no es generado el código es el siguiente:
System.IO.Stream incomingStream = context.Request.InputStream; //Get the incoming stream
System.Drawing.Image img = System.Drawing.Image.FromStream(incomingStream); //Create and image from the stream
int pageHeight = img.Height + (_Margin * 2);
int pageWidth = img.Width + (_Margin * 2);
Application WordApp = new Application();
Document WordDoc = WordApp.Documents.Add();
Range rng = WordDoc.Range(ref start, ref end);
PictWriter pw = new PictWriter(img, "Example Image", "Example Image");
rng.InsertXML(pw.ToString(), transform);
Object fileName = PHYSICAL_FILE_NAME;
Object fileFormat = Type.Missing;
Object lockComments = Type.Missing;
Object password = Type.Missing;
Object addToRecentFiles = Type.Missing;
Object writePassword = Type.Missing;
Object readOnlyRecommended = Type.Missing;
Object embedTrueTypeFonts = Type.Missing;
Object saveNativePictureFormat = Type.Missing;
Object saveFormsData = Type.Missing;
Object saveAsAOCELetter = Type.Missing;
Object encoding = Type.Missing;
Object insertLineBreaks = Type.Missing;
Object allowSubstitutions = Type.Missing;
Object lineEnding = Type.Missing;
Object addBiDiMarks = Type.Missing;
WordDoc.SaveAs(ref fileName, ref fileFormat, ref lockComments,
ref password, ref addToRecentFiles, ref writePassword,
ref readOnlyRecommended, ref embedTrueTypeFonts,
ref saveNativePictureFormat, ref saveFormsData,
ref saveAsAOCELetter, ref encoding, ref insertLineBreaks,
ref allowSubstitutions, ref lineEnding, ref addBiDiMarks);
object SaveChanges=Type.Missing;
object OriginalFormat=Type.Missing;
object RouteDocument=Type.Missing;
//WordApp.ActiveDocument.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
WordDoc.Close(ref SaveChanges, ref OriginalFormat,ref RouteDocument);
WordApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
//ReleaseComObject;
if (WordApp != null)
{
try
{
WordApp = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp);
}
catch (Exception ex)
{
}
}
GC.Collect();
GC.WaitForPendingFinalizers();
He estado investigando en internet y pues ya puse todo lo ke me indicaron, el Quit para la aplicación, el realeas y el Collect, pero aún así cuando ejecuto mi aplicación desde el servidor IIS no me lo cierrra, alguna idea??
Gracias a todos

Tengo na palicación, la cual genera un archivo en WORD y le incrusta una imagen, al momento de correrlo desde mi Visual Estudio, todo bien, me genera el documento sin mayor problema, pero al momento de publicarlo en mi servidor de IIS ya no me cierra la aplicación y por ende el archivo no es generado el código es el siguiente:
System.IO.Stream incomingStream = context.Request.InputStream; //Get the incoming stream
System.Drawing.Image img = System.Drawing.Image.FromStream(incomingStream); //Create and image from the stream
int pageHeight = img.Height + (_Margin * 2);
int pageWidth = img.Width + (_Margin * 2);
Application WordApp = new Application();
Document WordDoc = WordApp.Documents.Add();
Range rng = WordDoc.Range(ref start, ref end);
PictWriter pw = new PictWriter(img, "Example Image", "Example Image");
rng.InsertXML(pw.ToString(), transform);
Object fileName = PHYSICAL_FILE_NAME;
Object fileFormat = Type.Missing;
Object lockComments = Type.Missing;
Object password = Type.Missing;
Object addToRecentFiles = Type.Missing;
Object writePassword = Type.Missing;
Object readOnlyRecommended = Type.Missing;
Object embedTrueTypeFonts = Type.Missing;
Object saveNativePictureFormat = Type.Missing;
Object saveFormsData = Type.Missing;
Object saveAsAOCELetter = Type.Missing;
Object encoding = Type.Missing;
Object insertLineBreaks = Type.Missing;
Object allowSubstitutions = Type.Missing;
Object lineEnding = Type.Missing;
Object addBiDiMarks = Type.Missing;
WordDoc.SaveAs(ref fileName, ref fileFormat, ref lockComments,
ref password, ref addToRecentFiles, ref writePassword,
ref readOnlyRecommended, ref embedTrueTypeFonts,
ref saveNativePictureFormat, ref saveFormsData,
ref saveAsAOCELetter, ref encoding, ref insertLineBreaks,
ref allowSubstitutions, ref lineEnding, ref addBiDiMarks);
object SaveChanges=Type.Missing;
object OriginalFormat=Type.Missing;
object RouteDocument=Type.Missing;
//WordApp.ActiveDocument.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
WordDoc.Close(ref SaveChanges, ref OriginalFormat,ref RouteDocument);
WordApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
//ReleaseComObject;
if (WordApp != null)
{
try
{
WordApp = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp);
}
catch (Exception ex)
{
}
}
GC.Collect();
GC.WaitForPendingFinalizers();
He estado investigando en internet y pues ya puse todo lo ke me indicaron, el Quit para la aplicación, el realeas y el Collect, pero aún así cuando ejecuto mi aplicación desde el servidor IIS no me lo cierrra, alguna idea??

Gracias a todos

Valora esta pregunta


0