开发者

Custom file download in mvc difficulty

I am trying to work out the example from http://haacked.com/archive/开发者_如何学Go2008/05/10/writing-a-custom-file-download-action-result-for-asp.net-mvc.aspx, however, I am having the error message:

Access to the path 'C:\Dev\myproject\zippedFile' is denied.

or can I have an example of file downloading in MVC

Help please. Thanks


ASP.NET application pool identity (SYSTEM\NETWORK SERVICE by default) must have read access to the directory holding the file(s).


In your controller:

    [HttpPost]
    public ActionResult Upload(HttpPostedFileBase file)
    {
        if (file != null)
        {
            file.SaveAs("file path goes here" + file.FileName);
        }
        return View();
    }

In your view:

@using (Html.BeginForm("Upload", "ControllerName", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    <input type="file" name="file" />
    <input type="submit" value="Upload" />
}

And like Mathieu says, make sure where ever you are storing the files, your worker process has access to it. Best bet is to store the files within the site /Upload for example.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜