Ver Mensaje Individual
  #11 (permalink)  
Antiguo 04/08/2009, 09:08
Susana_Maria
 
Fecha de Ingreso: junio-2009
Mensajes: 12
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: cambiar formato .doc a .txt

ahi va:
public void transformar_word_a_txt(string ruta_docu)
{
FileInfo file = new FileInfo(ruta_docu);
if (file.Exists)
{
Word.Application word_app = new Word.Application();
//hasta ahi se ejecuta en el servidor el resto no se si se ejecuta Object saveChanges = Word.WdSaveOptions.wdSaveChanges;
Object fileName = file.FullName;
Object readOnly = false;
Object visible = true;
Object nullobj = Missing.Value;
Object docType = Word.WdDocumentType.wdTypeDocument;
Word.Document doc = word_app.Documents.Open(ref fileName, ref nullobj, ref readOnly, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);
string[] para_nombretxt = ruta_docu.Split('/');
string[] nombretxt = para_nombretxt[5].Split('.');
string nombre_doc_txt = cadena + nombreServidor + '/' + para_nombretxt[1] + '/' + para_nombretxt[2] + '/' + "documentosTxt" + '/' + nombretxt[0] + ".txt";
hd_ruta_doctxt.Value = nombre_doc_txt;
string unidad = "c:";
string nom_doc_txt = set_ruta_doc_txt(unidad + '/' + para_nombretxt[1] + '/' + para_nombretxt[2] + '/' + "documentosTxt" + '/' + nombretxt[0] + ".txt");
string[] paraFileName = nom_doc_txt.Split(':');

Object FileNametxt = unidad + paraFileName[1].ToString();

Object FileFormat = Word.WdSaveFormat.wdFormatText;
Object Encoding = MsoEncoding.msoEncodingEBCDICLatinAmericaSpain;
Object lookComents = true;
Object password = nullobj;
Object addTorecent = false;
Object writePassword = nullobj;
Object Readonly = false;
Object embedttfonts = false;
Object savenativepictures = true;
Object saveforms = false;
Object saveaocelater = false;
Object insertlines = true;
Object allowSubstition = true;
Object lineEnding = WdLineEndingType.wdCRLF;
Object addBidimarks = false;
try
{

doc.SaveAs(ref FileNametxt, ref FileFormat, ref nullobj, ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref saveforms, ref saveaocelater,
ref nullobj, ref insertlines, ref nullobj, ref nullobj, ref nullobj);

doc.Close(ref nullobj, ref nullobj, ref nullobj);
word_app.Quit(ref nullobj, ref nullobj, ref nullobj);
}


catch (ExternalException ex)
{
Response.Write("error:"+ ex.Message);
Object refe = System.Reflection.Missing.Value;
doc.Close(ref refe, ref refe, ref refe);
word_app.Quit(ref refe, ref refe, ref refe);
}
}
}

Este código funciona en mi maquina es decir con Local, pero en el IIS no se queda como colgado, creo que es porque no se cierra Word.Application en el IIS, viendo el administrador de tareas hay un proceso de ASPNET(usuario que agrege para que funcionara en el servidor) WINWORD.exe que queda abierto. No estoy muy segura pero creo que puede ser por esto. auxilio!!!:(