asp.net FileUpload 上传问题

chenluyu_8 2009-03-20 09:40:42

如何将本地的文件上传到远程的服务器上去?
用FileUpload如何实现呢?
请高手指教,回复必给分。
...全文
197 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
chenluyu_8 2009-04-14
  • 打赏
  • 举报
回复
OK
houndsky 2009-03-22
  • 打赏
  • 举报
回复
youthkin 2009-03-20
  • 打赏
  • 举报
回复
网上一堆的.你搜搜
spring1_ 2009-03-20
  • 打赏
  • 举报
回复
if(File1.PostedFile.FileName!=""&&File1.PostedFile.ContentLength>0)
string filename=System.Guid.NewGuid().ToString();
string aa=File1.PostedFile.FileName;
aa=aa.Substring(aa.LastIndexOf('\\')+1);
string ext=System.IO.Path.GetExtension(File1.PostedFile.FileName).ToLower().Trim();
filename=filename+ext;
string bb=System.Configuration.ConfigurationSettings.AppSettings["UpLoadRoot"].ToString();
File1.PostedFile.SaveAs(bb+filename);

其中UpLoadRoot是在web.config中定义好的。
<configuration>
<appSettings>

<add key="UpLoadRoot" value="E:\ID_upfile\" />
<add key="HttpDownLoadRoot" value="http://localhost/ID_upfile/" />
<add key="DownLoadRoot" value="http://localhost/ID_upfile/" />

</appSettings>
</configuration>
  • 打赏
  • 举报
回复
注释很容易理解哦
qq196260188 2009-03-20
  • 打赏
  • 举报
回复
楼上有代码了
scyinhui 2009-03-20
  • 打赏
  • 举报
回复
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
try
{
FileUpload1.SaveAs("C:\\Uploads\\" +
FileUpload1.FileName);
Label1.Text = "File name: " +
FileUpload1.PostedFile.FileName + "<br>" +
FileUpload1.PostedFile.ContentLength + " kb<br>" +
"Content type: " +
FileUpload1.PostedFile.ContentType;
}
catch (Exception ex)
{
Label1.Text = "ERROR: " + ex.Message.ToString();
}
else
{
Label1.Text = "You have not specified a file.";
}
}
takako_mu 2009-03-20
  • 打赏
  • 举报
回复

if (inputFile.PostedFile.ContentLength > 0)
{
string ServiceUrl = "";

//设定上传文件的保存路径为doc文件夹,请更正为服务器的IP
string strSaveDir = Server.MapPath("../") + "/doc/";

//对应Oracle中的PhysicalPath
string PhysicalPath = "doc";

//取得用户端上完整的档案名称
string strName = inputFile.PostedFile.FileName;

//取得文件名(抱括路径)里最后一个"."的索引 .doc .txt等后缀前的那个“.”
int intExt = strName.LastIndexOf(".");

//取得文件后缀名(扩展名)
string strExt = strName.Substring(intExt);

//根据日期和文件大小不同为文件命名,确保文件名不重复
DateTime datNow = DateTime.Now;
string strNewName1 = datNow.DayOfYear.ToString() + inputFile.PostedFile.ContentLength.ToString();// +strExt;

//取得文件名(包括路径)里最后一个"\"的索引
int intPath = strName.LastIndexOf("\\");

//取得文件名(不包括路径)
string strNewName = "\\" + strNewName1 + strName.Substring(intPath + 1);

//对应Oracle中的FileName
string FileName = strNewName1 + strName.Substring(intPath + 1);

//Server.MapPath()
inputFile.PostedFile.SaveAs(strSaveDir + strNewName);
ServiceUrl = strSaveDir + strNewName;

ChkAttachmentID = myCreateFactory.UploadAttachment(AttachmentID, FileName, PhysicalPath, NoticeID, txtAttachmentDes.Text.Trim(), User.Identity.Name.ToString());

if (ChkAttachmentID == 1)
{
labBulletin.Text = "Upload announcement success";
labAttachment.Text = "Upload Annex success";
//Response.Write("<script>(alert('上傳布告和附件成功'))</script>");
}
else
{
labAttachment.Text = "";
labBulletin.Text = "Upload announcement success";
}
}
}

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧