嗨我在asp.net中的文件上传错误 [英] hi iam getting error in file uploading in 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
Error 3 ; expected E:\mine\WebSite19\fileupload.aspx.cs 17 61 WebSite19
Error 18 A namespace does not directly contain members such as fields or methods E:\mine\WebSite19\fileupload.aspx.cs 38 7 WebSite19
Error 6 Invalid token '(' in class, struct, or interface member declaration E:\mine\WebSite19\fileupload.aspx.cs 23 22 WebSite19
Error 19 Type or namespace definition, or end-of-file expected E:\mine\WebSite19\fileupload.aspx.cs 49 1 WebSite19
推荐答案
1.您管理上传的方法不行。您正在尝试根据文件信息构建字符串构建器,然后你忘了使用结果将结果设置为你的标签。你应该将你的字符串生成器的结果也用于IF分支。
2.下一行代码:
1.Your approach for manage the upload is not OK. You are trying to build a string builder based on the file info, then you forgot to use the result by setting result to your label. You should use the result of your string builder also for IF branch.
2.The next line of code:
FileUpload1.SaveAs("<c:\\SaveDirectory>" + FileUpload1.FileName);
必须更改为:
must be change in:
FileUpload1.SaveAs("c:\\SaveDirectory" + FileUpload1.FileName);
3.欲了解更多详情,请参阅下一个链接:
http://msdn.microsoft.com/en-us/library/aa479405.aspx [ ^ ]
使用ASP.NET上传文件 [ ^ ]
我只解决了自己.........
i solved my self only .........
这篇关于嗨我在asp.net中的文件上传错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!