Blank document is created when using aspose.words on server

Hello, I am using aspose.words to create Word documents in a c# web application. When I run the code the locally on my pc the doc creates great. However, when I run from my server it creates a blank document. I have adjusted security on the folder c:\loans. I suspect it is a security issue but do not know what else to modify. I given Network Service modify access. Thank you for looking


case “Word”:
{
FileInfo templateFile = new FileInfo(inputFilePath);
FileInfo outputFile = new FileInfo(“C:\loans\test.doc”);
Object oTemplateDocument = templateFile.FullName;
Object oOutputDocument = outputFile.FullName;

// Create Word application instance
Word.Application wordApp = null;
Word.Document wordDoc = null;

try
{
wordApp = new Word.Application();
wordApp.Visible = false;
wordDoc = wordApp.Documents.Add(ref oTemplateDocument, Missing.Value, Missing.Value, Missing.Value);

// Go through each range (header, body, etc)…
foreach (Word.Range range in wordDoc.StoryRanges)
{
// Go through each Content Control field…
foreach (Word.ContentControl control in range.ContentControls)
{
// Try to find a match in the DB of how to populate this field…
WorkbookField field = fields.Where(f => f.FieldName == control.Title)
.Select(f => f)
.DefaultIfEmpty(null)
.FirstOrDefault();

Hi Diane,


Thanks for your inquiry. The code you posted is specific to Microsoft Word Automation; please attach the piece of Aspose.Words’ code which is causing this problem on your end. Also, is there any error message or log you can post here for our reference?

Best regards,

Hi - thanks for the reply. I think this is the code you are referring to, yes?


public class GetDoc : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString[“docName”] != null && context.Request.QueryString[“projectID”] != null)
{
int projectID = int.Parse(context.Request.QueryString[“projectID”]);
string templateDoc = context.Request.QueryString[“DocName”];
if (projectID != 0 && !string.IsNullOrEmpty(templateDoc))
{
Stream outputStream = new MemoryStream();

// Set contenttype and clear headers
context.Response.Clear();

switch (DocGenerator.GetDocumentType(templateDoc))
{
case DocumentType.PDF:
context.Response.ContentType = “application/pdf”;
DocGenerator.GenerateDocument(projectID, templateDoc, ref outputStream);
break;
case DocumentType.WORD_DOC:
case DocumentType.WORD_DOCX:
case DocumentType.WORD_DOTM:
context.Response.ContentType = “application/msword”;
DocGenerator.GenerateDocument(projectID, templateDoc, ref outputStream);
break;
default:
outputStream = new MemoryStream(DocGenerator.GetRawFile(templateDoc));
break;
}

// Write the memory stream to response stream
MemoryStream stream = (MemoryStream)outputStream;
stream.WriteTo(context.Response.OutputStream);

string saveAs = context.Request.QueryString[“OutputDocName”];
if (!string.IsNullOrEmpty(saveAs))
context.Response.AddHeader(“content-disposition”, “attachment;filename=”" + saveAs + “”");
else
context.Response.AddHeader(“Content-Disposition”, “attachment; filename=”" + templateDoc + “”");

// Buffer response so that page is sent
// after processing is complete.
context.Response.BufferOutput = true;

// Send the output to the client.
context.Response.Flush();
}
}
}

Hi Diane,


Thanks for the additional information. I tried running your code but unfortunately it is giving compile time errors (e.g. DocGenerator class is missing). To ensure a timely and accurate response, it would be great if you please create a standalone simple ASP.NET application that helps me reproduce your problem on my end and attach it here for testing. As soon as you get this simple application ready for me, I’ll start investigation into your issue and provide you more information.

Best regards,