asp.net - Getting error when opening word document using Word Interop C# -


enter image description here

this keeps comming when i'm downloading word document, when reopen it, works without problems.

this code:

                object missing = missing.value;             object start1 = 0;              var wordapp = new applicationclass();              microsoft.office.interop.word.document mydoc = wordapp.documents.add(ref missing, ref missing,                                                                                  ref missing, ref missing);              object donotsavechanges = wdsaveoptions.wddonotsavechanges;             //object filestream = new filestream(server.mappath("~/upload/") + filename,             //                                                  filemode.create);              object fs = server.mappath("~/upload/") + filename;              range rng = mydoc.range(ref start1, ref missing);              try             {                 mydoc.application.activedocument.saveas(ref fs, ref missing, ref missing, ref missing,                                                         ref missing, ref missing, ref missing, ref missing,                                                         ref missing, ref missing,                                                         ref missing, ref missing, ref missing, ref missing,                                                         ref missing, ref missing);                  wordapp.visible = true;        //all document information code here     }             catch (exception)             {                  throw;             }                         {                 mydoc.save();                  mydoc.close(ref donotsavechanges, ref missing, ref missing);             }              // file name used save file client's system..              string filename = fs.tostring();             system.io.stream stream = null;             try             {             // open file stream.                  stream = new filestream(filename, system.io.filemode.open, system.io.fileaccess.read,                                         system.io.fileshare.read);             // total bytes read:                  long bytestoread = stream.length;                 response.contenttype = "application/msword";                 response.addheader("content-disposition", "attachment; filename=" + filename);             // read bytes stream in small portions.                  while (bytestoread > 0)                 {             // make sure client still connected.                      if (response.isclientconnected)                     {            // read data buffer , write              // output stream.                          byte[] buffer = new byte[10000];                         int length = stream.read(buffer, 0, 10000);                         response.outputstream.write(buffer, 0, length);                         response.flush();             // have read bytes.. need read              // remaining.                          bytestoread = bytestoread - length;                     }                     else                     {             // out of loop, if user not connected anymore..                          bytestoread = -1;                     }                 }             }             catch (exception ex)             {                 response.write(ex.message);             // error occurred..              }                         {                 if (stream != null)                 {                     stream.close();                 }             }     } 

for repairing corrupted word file, should try third party software recoveryfix word recovery tool. tool in restoring word file.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -