数据库在这里的操作可以直接Sql insert 也可以Create Procedure ALTER procedure L_2MsikUpdateAppendFile @MissionWorkID int, @Msik_AppendFile varchar(80), @returnresult int output as update L_mainTable set Msik_AppendFile=@Msik_AppendFile where MissionWorkID=@MissionWorkID set @returnresult=@@ERROR 上面 Msik_AppendFile 保存的是文件名称 根据数据表里面的的一个唯一性MissionWorkID
OleDbConnection myConnection=new OleDbConnection(conn); string sqldelfile="select * from fq_email where email_jslogin1='"+Request["email_jslogin1"]+"' and email_id="+Request["email_id"];
OleDbDataAdapter dadelfile=new OleDbDataAdapter(sqldelfile,myConnection);
DataSet dsdelfile=new DataSet();
dadelfile.Fill(dsdelfile,"host");
string file=dsdelfile.Tables["host"].Rows[0][10].ToString();
string path = @"D:\yzc112\OA系统\govoa\email\upfile1+file";
try
{
using (StreamWriter sw = File.CreateText(path)) {}
string path2 = path + "temp"; // Ensure that the target does not exist.
File.Delete(path2); // Copy the file.
File.Copy(path, path2);
Console.WriteLine("{0} was copied to {1}.", path, path2); // Delete the newly created file.
File.Delete(path2);
Console.WriteLine("{0} was successfully deleted.", path2);
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
this.DataBind();
通过什么触发事件来删除呢?
这个问题我刚处理过,给你个思路,代码挺多的。贴出来太多
1 客户端上传文件 http://www.cnblogs.com/jhtchina/articles/82509.html 看我的博客
private string uploadFile()
{
try
{
string UploadFullFileName;
string uploadFileFullName;//FilePath,FileName
//uploadFileFullName=btnuploadFile.Value;
uploadFileFullName=Fileupload.Value;
int i=uploadFileFullName.LastIndexOf("\\");
string FileName=uploadFileFullName.Substring(i+1);
//string strPath=;//»ñµÃ·þÎñÆ÷¶ËµÄµ±È¨Ä¿Â¼
//uploadFileFullName=strPath+FileName;
string uploadFilePath=ConfigurationSettings.AppSettings["uploadFilePath"];
string ClientIP=Request.UserHostAddress;//¿Í‘ôÂZücIP
string strIP="";
//„hµôÆäÖеÄ.
for (int itemp=0;itemp<ClientIP.Length;itemp++)
{
if (ClientIP[itemp]=='.')
{
strIP+="-";
continue;
}
strIP+=ClientIP[itemp];
}
strIP+="--";
//µÃµ½®”Ç°•rég
string strGetDateTime=DateTime.Now.ToString();
string strDateTime="";
for (int itemp=0;itemp<strGetDateTime.Length;itemp++)
{
if ((strGetDateTime[itemp]==' ')||(strGetDateTime[itemp]==':')||(strGetDateTime[itemp]=='/'))
{
strDateTime+="-";
continue;
}
strDateTime+=strGetDateTime[itemp];
}
string strFullFileName=strIP+strDateTime;//‚€µ½ÉÏ‚÷ÒÔºóµÄÎļþÃû·Q
Fileupload.PostedFile.SaveAs(uploadFilePath+strFullFileName);
UploadFullFileName=strFullFileName;
return UploadFullFileName;//±£´æµÄÊÇÎļþ,¼UʽÊÇÀM½yÖ¸¶¨µÄÄ¿ä› }
catch
{
return null;
}
}
uploadFilePath=ConfigurationSettings.AppSettings["uploadFilePath"]; 获得服务器上传文件的相对位置.
这些做完以后,开始写数据库strUploadFullFileName=uploadFile();
MsiProcessClass MsiPC=new MsiProcessClass((string)Session["strConn"]); int iMissionWorkID=int.Parse(savevalue2.Text);
if (MsiPC.b_UploadMsikUpdateAppendFile(iMissionWorkID,strUploadFullFileName))
{
lbShowFileContent.Text=strUploadFullFileName;
Response.Write("<script>window.alert('Update OK£¡');</script>");
btnUploadFile.Visible=false;
ShowDataGrid();
}
else
{
Response.Write("<script>window.alert('Update Error£¡');</script>");
}
@MissionWorkID int,
@Msik_AppendFile varchar(80),
@returnresult int output
as
update L_mainTable
set Msik_AppendFile=@Msik_AppendFile
where MissionWorkID=@MissionWorkID
set @returnresult=@@ERROR
上面 Msik_AppendFile 保存的是文件名称 根据数据表里面的的一个唯一性MissionWorkID
同理,如果再次上传,则删除指定目录: uploadFilePath=ConfigurationSettings.AppSettings["uploadFilePath"];
下面的Msik_AppendFile从新上传就OK了
{
System.IO.File.Delete(Server.MapPath(filePath));
}
filePath是从数据库里取出来的相对路径:如../temp/fileName也可以
if(System.IO.File.Exists(filePath))
{
System.IO.File.Delete(filePath);
}filePath是从数据库里取出来的绝对路径:如C:\Inetpub\wwwroot\EHS\temp\fileName