本文介绍了嗨我在asp.net中的文件上传错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码背后...........



code behind ...........

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class fileupload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnsave_Click(object sender, EventArgs e)
    StringBuilder sb = new StringBuilder();
   if (FileUpload1.HasFile)
   {
      try
      {
      sb.AppendFormat(" Uploading file: {0}",
                                  FileUpload1.FileName);
      //saving the file
      FileUpload1.SaveAs("<c:\\SaveDirectory>" +
                                  FileUpload1.FileName);
      //Showing the file information
      sb.AppendFormat("<br/> Save As: {0}",
                         FileUpload1.PostedFile.FileName);
      sb.AppendFormat("<br/> File type: {0}",
                         FileUpload1.PostedFile.ContentType);
      sb.AppendFormat("<br/> File length: {0}",
                         FileUpload1.PostedFile.ContentLength);
      sb.AppendFormat("<br/> File name: {0}",
                         FileUpload1.PostedFile.FileName);
      }
      catch (Exception ex)
      {
      sb.Append("<br/> Error <br/>");
      sb.AppendFormat("Unable to save file <br/> {0}",
                         ex.Message);
      }

   else
   {
      lblmessage.Text = sb.ToString();
   }
}





错误是





错误3;预期E:\mine \WebSite19 \ fileupload.aspx.cs 17 61 WebSite19

错误18命名空间不直接包含字段或方法等成员E:\mine\WebSite19 \\ \\ fileupload.aspx.cs 38 7 WebSite19

错误6无效的标记'('在类,结构或接口成员声明中E:\\\\\\\\\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ WebSite19





错误19类型或命名空间定义,或期望的文件结束E:\mine\WebSite19 \ fileupload .aspx.cs 49 1 WebSite19



error is


Error3; expectedE:\mine\WebSite19\fileupload.aspx.cs1761WebSite19
Error18A namespace does not directly contain members such as fields or methodsE:\mine\WebSite19\fileupload.aspx.cs387WebSite19
Error6Invalid token '(' in class, struct, or interface member declarationE:\mine\WebSite19\fileupload.aspx.cs2322WebSite19


Error19Type or namespace definition, or end-of-file expectedE:\mine\WebSite19\fileupload.aspx.cs491WebSite19

推荐答案

FileUpload1.SaveAs("<c:\\SaveDirectory>" + FileUpload1.FileName);



必须更改为:


must be change in:

FileUpload1.SaveAs("c:\\SaveDirectory" + FileUpload1.FileName);





3.欲了解更多详情,请参阅下一个链接:

[]

[]



这篇关于嗨我在asp.net中的文件上传错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:24