Dezmen Ceo Sykes
Dezmen Ceo Sykes

Reputation: 301

ASP.NET MVC 4 - Uploading files to a server

I'm trying to upload a file to my website using a method I found on the net. When i upload files in debug mode, it works fine, but when I try to upload on my website, I get this error.

Access to the path 'D:\Hosting\11029316\html\gizmoblog\Content\Images\dpi.jpg' is denied.

This is the method I'm using to upload files.

public ActionResult UpdateLogo(HttpPostedFileBase SiteLogo)
{
   if (SiteLogo.ContentLength > 0)
   {
       var fileName = Path.GetFileName(SiteLogo.FileName);
       var path = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
       SiteLogo.SaveAs(path);
   }
}

Is there a way I can upload the file using a FTP stream? Or even upload them using a URI to my website like http://www.weburl.com/uploads/filename? Really need help guys..

Upvotes: 0

Views: 3305

Answers (1)

Jason Yost
Jason Yost

Reputation: 4937

This is a permissions issue on your server. On your local machine you are running under the context of your current user, which allows you to write to your disk. On the server, the IIS worker process needs permission to write to the uploads directory (it is not allowed by default for security). See this link for more information

http://support.microsoft.com/kb/979124

To answer your other questions, uploading via an FTP stream is more complex and not necessary since the .NET framework includes everything you need to accept a file upload and save it.

You might also be interested in trying out http://filepicker.io which offers a simple way to handle file management through an API.

Upvotes: 1

Related Questions