Click here to Skip to main content
15,868,058 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I created a button that saves the webpage as an html file and prompts the user to save it. It works fine when I am testing it locally, but when I publish it to the test server, I get the following error:

The remote server returned an error: (401) Unauthorized. 


The codeis as follows:

Protected Sub btnSaveAsHtml_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSaveAsHtml.Click

<pre>Dim url As String
        url = "http://test.intranet.company.com/ESTaxCalculator/"
        Dim wc As System.Net.WebClient = New System.Net.WebClient
        'wc = Nothing
        Dim path As String
        path = "C:\inetpub\temp\"
        Dim filename2 As String
        filename2 = "E&Shtml.html"
        wc.DownloadFile(url, path + filename2)
        Response.ClearContent()
        Response.ClearHeaders()
        Response.AddHeader("ContentType", "application/octet-stream")
        Response.AddHeader("Content-Disposition", "attachment;   filename=E&Shtml.html")
        Response.WriteFile(path + filename2)
        Response.End()


The url for testing locally is different than what is there now.

I have searched elsewhere but am unable to find anything that has helped me yet. I would appreciate any guidance.

Thank you.
Posted
Updated 9-Jul-12 5:30am
v3
Comments
[no name] 9-Jul-12 11:19am    
Is your web applicaiton authorized to read/write to that file path?
Richard C Bishop 9-Jul-12 11:31am    
I am not exactly sure, is that something I would check in the IIS?
[no name] 9-Jul-12 11:32am    
That's where I would start.
Richard C Bishop 9-Jul-12 11:37am    
Ok, I checked there and it appears that all the users or groups have permission to write to the file. That is under Propertines then Security tab right?

Any other suggestions?
[no name] 9-Jul-12 11:44am    
Check to make sure that the account that your web applicaiton is running under has permission to write to that directory.

1 solution

I ended changing how I was capturing the current web page and it is working now.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900