Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Feb 27, 2015 12:54 pm

I am using the free version and am trying to save a document to a certain folder in asp.net.

It wont save to the folder I choose, it instead always saves to the My Documents folder.

This is my code:

'Create word document
Dim document_Renamed As New Document()

'load a document
document_Renamed.LoadFromFile(Server.MapPath(("~/App_Data/FindAndReplace.doc")))



document_Renamed.Replace(Me.TextBox1.Text, Me.TextBox2.Text, True, True)

document_Renamed.SaveToFile(Server.MapPath(("~/App_Data/Sample.doc")), FileFormat.Doc, Response, HttpContentType.Attachment)

It will load a document from the App_Data folder but will not save to that folder.

What am I doing wrong?

Paul

paulgreen
 
Posts: 3
Joined: Fri Feb 13, 2015 11:12 am

Sat Feb 28, 2015 2:34 am

Dear Paul,

Thanks for your inquiry.
You can try the following code:
Code: Select all
document_Renamed.SaveToFile (@"..\App_Data\Sample.doc", FileFormat.Doc);

If there are any questions, welcome to get it back to us.

Best Regards,
Betsy
Last edited by Betsy on Sat Feb 28, 2015 6:00 am, edited 1 time in total.
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Sat Feb 28, 2015 4:32 am

HI Betsy,

Your code will not even run, I get error message "Expression expected", the @ is underlined.

I use VB.Net. I tried replacing the @ with ~ (tilde) but it didn't help.

Regards Paul

paulgreen
 
Posts: 3
Joined: Fri Feb 13, 2015 11:12 am

Sat Feb 28, 2015 6:05 am

Dear Paul,

Sorry that the code is used in C#.
You can try the following code:
Code: Select all
document_Renamed.SaveToFile("..\App_Data\Sample.doc", FileFormat.Doc)

If there are any questions, welcome to get it back to us.

Best Regards,
Betsy
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Sat Feb 28, 2015 6:14 am

HI Betsy,

Your code gives the following error:

Additional information: Could not find a part of the path 'C:\Program Files (x86)\App_Data\Sample.doc'

However I found a way to make it work:

Dim filename As String = Server.MapPath("~/App_Data/Sample.doc")
document_Renamed.SaveToFile(filename, FileFormat.Doc)

Thanks for your help.

Paul

paulgreen
 
Posts: 3
Joined: Fri Feb 13, 2015 11:12 am

Sat Feb 28, 2015 6:52 am

Dear Paul,

I am glad to hear that your issue has been resolved by yourself.
Please feel free to contact us if you have any questions or needs.

Best Regards,
Betsy
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Return to Spire.Doc