Immer den Pfad der Datei aus HttpPostedFileBase

Arbeite ich mit ASP.NET MVC 4, und ich versuche, den Pfad der hochzuladenden Datei um Sie zu öffnen und zu manipulieren. Dies ist, wie ich fortfahren :

Controller

public ActionResult Bulk(HttpPostedFileBase file)
{
    FileStream fs = System.IO.File.Open(Server.MapPath(file.FileName), 
                                         FileMode.Open, FileAccess.Read);

    return RedirectToAction("Index");
}

Ansicht

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

    @using (Html.BeginForm("Bulk", "Bulk", null, FormMethod.Post, new 
                                          { enctype = "multipart/form-data" }))
    {
        @Html.ValidationSummary(true)

        <fieldset>
            <p>
                <input type="file" name="file"/>
            </p>
            <div class="form-actions">
              <button type="submit" class="btn btn-primary">Create</button>
            </div>
        </fieldset>
    }

Wenn ich das mache, bekomme ich eine Fehlermeldung, die sagt ... Could not find a part of the path ...

Wie bekomme ich den Pfad, wo meine Datei ist tatsächlich in der Lage?

InformationsquelleAutor Traffy | 2013-07-26

Schreibe einen Kommentar