开发者

Download and save aspx page

I saved aspx page as html it worked in my local machine but after published on the server its showing an error that "the access to the path is denied"... I tried giving access permission then also it doesn't work.. can anyone help with it? or else is there any other way to save the page in C# asp.net?...

string url=HttpContext.Current.Request.Url.AbsoluteUri;
string sHt开发者_运维问答ml="";
HttpWebRequest request;
HttpWebResponse response=null;
Stream stream=null;

request=HttpWebRequest)WebRequest.Create(url);
response=(HttpWebResponse)request.GetResponse();
stream=response.GetResponseStream(); 
StreamReader sr=new StreamReader(stream,System.Text.Encoding.Default);
sHtml=sr.ReadToEnd();

string path=Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string textfilename=TextBox1.Text; 
string getpath=path+"\\"+textfilename+".html";
File.WriteAllText(getpath,sHtml);

if(stream!=null)stream.Close();
if(response!=null)response.Close();

Thanks..


If you need to save a file use this to get the application path

Server.MapPath(@"filename.txt");

Try this because when you only write the filename at an web server you are trying to access to a Microsoft.Net folder.


yes make sure the folder you write to has the appropriate privileges. IIS 5 uses ASPNET account, IIS6 uses network service. Just give read/write to the proper account. Is this your dev environment, or a prod environment?

Also, make sure it's pointing to a folder; desktop folder for ASPNET account probably won't exist since ASPNET account isn't a user with a users folder.


I had a similar problem when trying to deploy CSS from a ZIP downloaded from the web. Try right-clicking on the aspx file from windows explorer and checking the file properties. One of the tabs may indicate that the file has been "blocked". If so, there will be a button there to unblock it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜