我需要上传一个 zip 文件,单击一个按钮并将其解压缩到同一文件夹中,并为该文件夹命名。我不知道从哪里开始,到目前为止我有上传部分:我的观点:
<% using (Html.BeginForm(null, null, FormMethod.Post, new { enctype = "multipart/form-data" }))
{ %>
<%: Html.ZincValidationSummary() %>
<%: Html.ZincValidationErrors() %>
<div class="section _100">
<%: Html.LabelFor(model => model.Name)%>
<div>
<%: Html.TextBoxFor(model => model.Name, new { maxlength = "100" })%>
<%: Html.ValidationMessageFor(model => model.Name)%>
</div>
</div>
<div class="section _100">
<%: Html.LabelFor(model => model.ScormPackageFile) %>
<div>
<br />
<input type="file" id="ScormPackageFile" name="ScormPackageFile" />
<%: Html.ValidationMessageFor(model => model.ScormPackageFile)%>
<br />
</div>
</div>
<div class="actions">
<div class="actions-right">
<input type="submit" value="<%: Html.Resource(Resources.Global.Button.Save) %>" class="submit_button" />
</div>
</div>
<% } %>
在控制器中:这是我不知道该怎么做的地方:
HttpPost]
public ActionResult Upload(ScormUploadViewModel model)
{
if (ModelState.IsValid)
{
if (model.ScormPackageFile != null)
{
string extractDir = "c:\\TSFPreview\\Zinc\\Web\\Project\\ScormPackages";
//I should get the above dir from the uploaded file's directory because the
unziped folder will be in the same folder
}
var smallImageUrl = MediaStorageService.UploadFromStream(Zinc.Media.MediaType.Attribute, model.ScormPackageFile.FileName, model.ScormPackageFile.ContentType, model.ScormPackageFile.InputStream);
//group.SmallImageUrl = smallImageUrl;
}
return View(model);
}
然后我的视图模型:
public class ScormUploadViewModel
{
[LocalizedRequired]
[DataType(DataType.Text)]
[LocalizedDisplayName(Resources.Global.Title.Name)]
public string Name { get; set; }
[DisplayName("Upload a scorm package")]
public HttpPostedFileBase ScormPackageFile { get; set; }
}
谢谢我不知道我现在应该添加什么其他标签我刚刚添加了 asp.net mvc 3 标签:)