We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Doc.save method overload error

Using this to save docx formatted documents and doc.save method I tried to use new way but does not work. I am trying to update the following method but just not working for .net framework 4.5.2.
Option 1: Old way does not work

doc.Save(LetterTemplateEntity.CRSC_LETTER_TEMPLATE_DESC + doctype,SaveFormat.FormatDocument, SaveType.OpenInWord, this.Response);

Option 2: New way also fails. What I am doing wrong:

doc.Save(this.Response, "LetterTemplateEntity.CRSC_LETTER_TEMPLATE_DESC + doctype", ContentDisposition.Inline, null);

@vlbuch23 Could you please elaborate your question a bit more? Do you get some error while using Document.Save method? What kind of application are you working on? The mentioned Document.Save works only in ASP.NET applications.
If possible, please create a sample application that demonstrates the problem and attach it here. We will check it and provide you more information.

yes it’s .net application using entities

doctype is basically spewing whether it’s a doc or not.

Basically we use that document.save method to save document and it’s .net framework is 4.5.2

I updated my binaries and license as well. But old method which used to take 5 over loads is not working.

doc.Save(LetterTemplateEntity.CRSC_LETTER_TEMPLATE_DESC + doctype,SaveFormat.FormatDocument, SaveType.OpenInWord, this.Response);

@vlbuch23 @surbhiksnkariya82 Thank you for additional information. Unfortunately, i do not see any attachments. Saving to response works as the following code:

using (MemoryStream stream = new MemoryStream())
    doc.Save(stream, SaveFormat.Pdf);

    //Specify the document type.
    Response.ContentType = "application/pdf";

    //Other options:
    //Response.ContentType = "text/plain"
    //Response.ContentType = "text/html"
    //Specify how the document is sent to the browser.
    Response.AddHeader("content-disposition", "attachment; filename=MyDocument.pdf");

    //Another option could be:
    //Response.AddHeader("content-disposition", "inline; filename=out.doc");
    //Get data bytes from the stream and send it to the response.
    byte[] bytes = stream.GetBuffer();


So for testing purposes you can try using this code to detect where exactly the problem occurs. Also, could you please share an error message, when you try using the mentioned overload?


I have that in my code. but original overload method to save document doc.save method does not work.


Could you please elaborate what you mean when say the method does not work? Does the method throw an exception? Or the output document is not sent the the browser? Is the output document corrupted?


Can I get a good working code which just saves document to browser and also checks if the license is valid or not.
Simple web or console app. Thanks much.

@vlbuch23 Here you are.TestAspNet.zip (9.1 KB)
This is a simple ASP.NET Web Forms application with only one page with button on it, which generates a simple document and sends it to the browser.
The license is applied on application starts (see Global.asax.cs). To make the licensing code work you have to include your license into the project as an embedded resource.

Yes. Can you send in a sample application for word as well. This similar to what I was looking for . I was able to to apply the license as embedded resource and remove the watermark.

@vlbuch23 The code is almost the same:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("Hello, World!!!");
doc.Save(Response, "test.docx", ContentDisposition.Attachment, new OoxmlSaveOptions());

Here is the modified project: TestAspNet.zip (9.1 KB)

Notifications.zip (24.9 KB)

Please find attached full code. CORB.Web -> CRSC -> GenerateNotification.aspx Lines 211 onwards I have utilized similar code from example you provided and this code was earlier also using doc.save method. Scorb.BusinessLogic -> TemplateEngine.CS has code for license.But I had changed to Global.asax as per example provided. I added license info in Application Start. I have copy pasted error below as well where its failing at SaveOptions click.
===================================ERROR =====================

Error Number: 396461fe-8e21-47e9-80c5-7dcc19f2a586
 User: surbhi.shah
 Error: System.Data.Entity.Infrastructure.DbUpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> Oracle.DataAccess.Client.OracleException: ORA-00001: unique constraint (SCORBAPP.SYS_C0019742) violated
   at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck, Int32 isRecoverable)
   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
   at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.<NonQuery>b__0(DbCommand t, DbCommandInterceptionContext`1 c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.NonQuery(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Internal.InterceptableDbCommand.ExecuteNonQuery()
   at System.Data.Entity.Core.Mapping.Update.Internal.DynamicUpdateCommand.Execute(Dictionary`2 identifierValues, List`1 generatedValues)
   at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.Mapping.Update.Internal.UpdateTranslator.Update()
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.<Update>b__2(UpdateTranslator ut)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update[T](T noChangesResult, Func`2 updateFunction)
   at System.Data.Entity.Core.EntityClient.Internal.EntityAdapter.Update()
   at System.Data.Entity.Core.Objects.ObjectContext.<SaveChangesToStore>b__35()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesToStore(SaveOptions options, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction)
   at System.Data.Entity.Core.Objects.ObjectContext.<>c__DisplayClass2a.<SaveChangesInternal>b__27()
   at System.Data.Entity.Infrastructure.DefaultExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChangesInternal(SaveOptions options, Boolean executeInExistingTransaction)
   at System.Data.Entity.Core.Objects.ObjectContext.SaveChanges(SaveOptions options)
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   --- End of inner exception stack trace ---
   at System.Data.Entity.Internal.InternalContext.SaveChanges()
   at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()
   at System.Data.Entity.DbContext.SaveChanges()
   at SCORB.BusinessLogic.NotificationLetterController.SaveNotificationHistory(TBL_NOTIFICATION_HISTORY entity) in C:\Source\corb-master (2)\corb-master\Source\SCORB.BusinessLogic\Controllers\NotificationLetterController.cs:line 263
   at CRSC_Notifications_GenerateNotificationLetters.GenerateNotificationLetter_Click(Object sender, EventArgs e) in C:\Source\corb-master (2)\corb-master\Source\CORB.Web\CRSC\Notifications\GenerateNotificationLetters.aspx.cs:line 152

----------End Logging-------------

Notifications.zip (24.9 KB)

Some more files

@vlbuch23 Thank you for additional information. But from your stack trace I see that the the exception is Data Base related. There is nothing about Aspose.Words in the provided stack trace.
Also, the exception occurs in the NotificationLetterController class. I do not see this class in the attached achieve. Could you please attach the mentioned class here for analysis and elaborate a bit more why you have concluded the problem is causes by Document.Save to Response overload?

Hi. I am attaching Notification.Controller and TemplateEngine.CS also which had license code. This is very old code I have seen. If you notice the end of the error it says about GenerateNotification.aspx.cs there is error showing for SaveOptions. Old code is working in Production which is having expired license. Strange to me but now they want me to update the license. Old overload method which SaveType and SaveInWord. Templates.zip (51.8 KB)

@vlbuch23 Thank you for additional information. But I do not see Aspose.Words.SaveOptions in the stack trace you have provided. From stack trace I see the error occurs in the following method:

public void SaveNotificationHistory(TBL_NOTIFICATION_HISTORY entity)
    using (SCORBEntities context = new SCORBEntities())
            entity.NOTIFICATION_HISTORY_ID = SequenceHelper.GetNextSequence("NOTIFICATION_HISTORY_ID"); 

Which seems to be related to the database interaction. In the stack trace you see System.Data.Entity.Core.Objects.SaveOptions. See ObjectContext.SaveChanges.

Ok. Did you check TemplateEnging controller as well? And Sometimes I get this error now. I did modify some code today.

Error Number: 46d0fc8f-527c-42cc-9876-f0481db1cbb5
 User: surbhi.shah
 Error: System.FormatException: Input string was not in a correct format.
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.Int32.Parse(String s)
   at CRSC_Notifications_GenerateNotificationLetters.GenerateNotificationLetter_Click(Object sender, EventArgs e) in C:\Source\corb-master (2)\corb-master\Source\CORB.Web\CRSC\Notifications\GenerateNotificationLetters.aspx.cs:line 190
doc.Save(Response, "LetterTemplateEntity.CRSC_LETTER_TEMPLATE.ToString().docx", Aspose.Words.ContentDisposition.Attachment, new OoxmlSaveOptions());
Response.AddHeader("Content-Disposition", "attachment; filename=" + LetterTemplateEntity.CRSC_LETTER_TEMPLATE.ToString());
 // this.Response.AddHeader("Content-Length", notification.LETTER.Length.ToString());

@vlbuch23 The error you have provided also is not related to Aspose.Words, it occurs in the following method:


Most likely SessionKeys.CaseId cannot be parsed as integer.

The code you have provided should look like the following:

doc.Save(Response, "LetterTemplateEntity.CRSC_LETTER_TEMPLATE.ToString().docx", Aspose.Words.ContentDisposition.Attachment, new OoxmlSaveOptions());

Ok make sense but should be AuthenticodeSigned dll or ClientSide. .NET framework I am using in production as well is 4.5.2 and goal is to allow client download via browser as it did before too. Just for reference we had something like before which worked in old dll using the one from before:

doc.Save(LetterTemplateEntity.CRSC_LETTER_TEMPLATE_DESC + doctype,
                          SaveFormat.FormatDocument, SaveType.OpenInWord, this.Response);

From which I will update as per your above code.
Also attached screen shot which dll should I be using. dll options.PNG (36.2 KB)

In global asax i have like following: -

License lic = new License();

I found the code for this. It was short to 16bit and it should be long integer?
public enum SessionKeys:long
PartyId = 1,