开发者

Accessing Files On A Hosted Asp.Net Site

I want to create an asp.net based website. When I create the sit eon my local machine I am uploading pdf files to my file system then accessing the files to view in my website. When I make the site go live how do I translatye this? Can I have开发者_StackOverflow files saved somehow with my interenet host? How would I access the files though the internet host on my application?


You will have to access those files with either a full or relative url.

For example, let's say you have directory in your site called \files\ where the pdf's are stored and you have a file in there called somefile.pdf

You would link to it by either "/files/somefile.pdf" or "http://mysite.com/files/somefile.pdf"


In your code-behind file, you'll want to assign a 'SaveAs' path name to your FileUpload control. This path determines where .NET will write PDF and any other files uploaded by your users.

For example:

FileUploadControl.SaveAs(Server.MapPath("~/") + filename);

Server.MapPath will set a directory path based upon the specific machine your app is running on: http://msdn.microsoft.com/en-us/library/ms524632(VS.90).aspx You can also specify a static directory path.

Then, you'll need to configure your web hosting account to enable file writes to the website directory you specified above. By default, nearly all hosting providers restrict file writes (such as file uploads) to website directories. Contact your web hosting service provider for directions on how to change permissions so that the .NET application can save your user uploaded files.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜