Hi,
I am using c# and allowed to use Microsoft Interop Word dll. But I do NOT want to save documents to temp folder and how to do that.
I have the code from you guys as below:
Note that i dont know how to get file path even since its in stored procedure. Thanks for any help i can get.
private void WriteWordFile(object filePath)
{
object missingType = Type.Missing;
object readOnly = true;
object isVisible = false;
object documentFormat = 8;
string randomName = DateTime.Now.Ticks.ToString();
object htmlFilePath = Server.MapPath("~/Temp/") + randomName + ".htm";
string directoryPath = Server.MapPath("~/Temp/") + randomName + "_files";
ApplicationClass applicationclass = new ApplicationClass();
applicationclass.Documents.Open(ref filePath,
ref readOnly,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref isVisible,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType);
applicationclass.Visible = false;
Document document = applicationclass.ActiveDocument;
document.SaveAs(ref htmlFilePath, ref documentFormat, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType, ref missingType, ref missingType,
ref missingType);
document.Close(ref missingType, ref missingType, ref missingType);
byte[] bytes;
using (FileStream fs = new FileStream(htmlFilePath.ToString(), FileMode.Open, FileAccess.Read))
{
BinaryReader reader = new BinaryReader(fs);
bytes = reader.ReadBytes((int)fs.Length);
fs.Close();
}
Response.BinaryWrite(bytes);
Response.Flush();
//File.Delete(htmlFilePath.ToString());
//foreach (string file in Directory.GetFiles(directoryPath))
//{
// File.Delete(file);
//}
//Directory.Delete(directoryPath);
//if (File.Exists(filePath.ToString()))
//{
// File.Delete(filePath.ToString());
//}
Response.End();
}