62,046
社区成员
发帖
与我相关
我的任务
分享
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";
}
}
}