文件的上傳功能! To 楼主,网上可以随便找到一个上传文件的源代码,至于你所的版本控制的问题,我目前正在做,我做的是XML文件的上传,我在里面加入了判断标志,上传的文件存在临时目录里面,然后做一个后台程序在临时目录不断寻找新的文件,判断,存入数据库,删除无用的文件,实现的过程不是很复杂,但是逻辑性一定要强! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 解决方案一:定义一个shi.xsl文件夹,在这个文件夹下用上传的日期作为文件名存储。要打开文件shi.xsl的时候,要判定是否存在这个文件夹,如果存在则在文件夹中根据要求打开对应的XSL文件解决方案二:建立一个文件列表的XML或数据库,对每个文件建立一个节点,然后在节点下记录文件上传信息,同时把文件名存储为一个随机字符串,比如guid字符串或System.DateTime.Now.Ticks等,XML结构如下:<Files> <File name="shi.xsl"> <UpLoadInfo> <UpLoadDate></UpLoadDate> <RealFileName></RelFileName> </UpLoadInfo> </File></Files>有多个文件就有多个File节点,一个文件有多次上传在文件对应的File下就有多个UpLoadInfo节点。当然这个XML很粗糙,还有很大的提炼空间。 在UpLoadDate中保存上传的日期,在RealFileName中保存文件上传的时候保存的文件名。 我在運行程序時系統報錯:拒絕存取路徑 "c:\inetpub\wwwroot\WebApplication1\images\study.txt"。請問是怎麽回事,並且在images中也找不到study.txt!請幫忙!!! private void Page_Load(object sender, System.EventArgs e) { if(this.IsPostBack) this.SaveImages(); } #region Web Form 設計工具產生的程式碼 override protected void OnInit(EventArgs e) { InitializeComponent(); base.OnInit(e); } private void InitializeComponent() { this.UploadButton.Click += new System.EventHandler(this.UploadButton_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion private Boolean SaveImages() { HttpFileCollection files = HttpContext.Current.Request.Files; System.Text.StringBuilder strMsg = new System.Text.StringBuilder(); strMsg.Append("上传的文件分别是:<hr color=red>"); try { for(int iFile = 0; iFile < files.Count; iFile++) { HttpPostedFile postedFile = files[iFile]; string fileName, fileExtension; fileName = System.IO.Path.GetFileName(postedFile.FileName); if(fileName!="") { fileExtension = System.IO.Path.GetExtension(fileName); strMsg.Append("文件类型:" + postedFile.ContentType.ToString() + "<br>"); strMsg.Append("文件地址:" + postedFile.FileName + "<br>"); strMsg.Append("文件名:" + fileName + "<br>"); strMsg.Append("文件扩展名:" + fileExtension + "<br><hr>"); postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName); } } strStatus.Text = strMsg.ToString(); return true; } catch(System.Exception Ex) { strStatus.Text = Ex.Message; return false; } } 代码没错。应该是你的文件夹image的权限引起的。 关于窗口中的一个问题,求解决方案 关于C#里的正则表达式 Image.FromStream报错参数无效 流 MemoryStream 与 UnmanagedMemoryStream 之间的问题 求解!! C#有没有办法获取DLL里面的函数名?DllImport出了点问题 如何用c#截取 一道邪门面试题: 交错数组的问题, 要了两张草稿纸也没作出来, 汗! 怎么用C#实现多搜索引擎 C# 向正在运行的exe传值 哪里有介绍C#的内置函数?比如时间格式化函数之类的. 设置按钮为热键?(在asp.net中用c#编写) 如何更改来自postedFile.InputStream的xml内容的编码
要打开文件shi.xsl的时候,要判定是否存在这个文件夹,如果存在则在文件夹中根据要求打开对应的XSL文件
解决方案二:建立一个文件列表的XML或数据库,对每个文件建立一个节点,然后在节点下记录文件上传信息,同时把文件名存储为一个随机字符串,比如guid字符串或System.DateTime.Now.Ticks等,XML结构如下:<Files>
<File name="shi.xsl">
<UpLoadInfo>
<UpLoadDate></UpLoadDate>
<RealFileName></RelFileName>
</UpLoadInfo>
</File>
</Files>有多个文件就有多个File节点,一个文件有多次上传在文件对应的File下就有多个UpLoadInfo节点。当然这个XML很粗糙,还有很大的提炼空间。
{
if(this.IsPostBack)
this.SaveImages();
} #region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.UploadButton.Click += new System.EventHandler(this.UploadButton_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion
private Boolean SaveImages()
{
HttpFileCollection files = HttpContext.Current.Request.Files;
System.Text.StringBuilder strMsg = new System.Text.StringBuilder();
strMsg.Append("上传的文件分别是:<hr color=red>"); try
{
for(int iFile = 0; iFile < files.Count; iFile++)
{
HttpPostedFile postedFile = files[iFile];
string fileName, fileExtension;
fileName = System.IO.Path.GetFileName(postedFile.FileName); if(fileName!="")
{
fileExtension = System.IO.Path.GetExtension(fileName);
strMsg.Append("文件类型:" + postedFile.ContentType.ToString() + "<br>");
strMsg.Append("文件地址:" + postedFile.FileName + "<br>");
strMsg.Append("文件名:" + fileName + "<br>");
strMsg.Append("文件扩展名:" + fileExtension + "<br><hr>");
postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("images/") + fileName); }
}
strStatus.Text = strMsg.ToString();
return true; }
catch(System.Exception Ex)
{
strStatus.Text = Ex.Message;
return false; } }