上传附件的问题,哪位能提供完整代码,在线等!!!!! 上传附件的问题,哪位能提供完整代码,在线等!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 if (UpLoad.PostedFile != null && UpLoad.PostedFile.FileName.Length > 0 ){HttpFileCollection objFiles = HttpContext.Current.Request.Files;HttpPostedFile objPostedFile = objFiles[0]; strOrgFileName = System.IO.Path.GetFileName(objPostedFile.FileName);strFileExtension = System.IO.Path.GetExtension(strOrgFileName);strCurFileName = Guid.NewGuid().ToString()+strFileExtension;objPostedFile.SaveAs(Server.MapPath("../Upload/CustPic/") + strCurFileName);} /// </summary> private void Upload() { if(txtPhoto.Value != "") { string sFileName = txtPhoto.PostedFile.FileName; string strFileExt = System.IO.Path.GetExtension(sFileName).ToString(); int nFileLength = Convert.ToInt32(txtPhoto.PostedFile.ContentLength.ToString()); string sUpPath = Server.MapPath("RESUMEPHOTO"); string sNewName = GetPhotoName(); //郪傖奻換腔俇淕繚噤 sUpPath += "\\" + sNewName; //瓚剿垀猁奻換腔恅璃跡宒岆祥岆珨跺磁楊腔恅璃跡宒 if(!sNewName.Equals("Error") && nFileLength < 1024 *50) { txtPhoto.PostedFile.SaveAs(sUpPath); } else { Session["Messages"] ="恅璃跡宒[gif,jpg,jpeg,png]麼恅璃湮衾50K"; Response.Redirect("../Error.aspx"); } } } <input type="file" size="53" id="txtPhoto" class="InputTxt" name="txtPhoto" onmouseover="ShowPhoto();" runat="server"> <INPUT class="inputcss" id="File1" style="WIDTH: 184px; HEIGHT: 19px" type="file" size="11" name="File1" runat="server">按钮:<asp:button id="cmdSubmit" runat="server" CssClass="redButtonCss" Width="60px" Text="发布" Height="20px"></asp:button>我想上传word或excel文档,请问程序应当个怎么写?由于初学,望大家多多帮助,代码最好有注释。谢谢! //如果有附件则上传 HttpPostedFile hpfFile = AttachFile.PostedFile; if(hpfFile.FileName!="") { //有附件,则上传到Temp目录中 //取得文件名(不含路径) char[] de = {'\\'}; string[] AFilename = hpfFile.FileName.Split(de); string strFilename = AFilename[AFilename.Length-1]; string strPath = Server.MapPath(".")+"\\Temp\\"+strFilename; hpfFile.SaveAs(strPath); //添加附件 MyMsg.Attachments.Add(new MailAttachment(strPath)); 新手求助 按钮text显示字母左右间距怎样修改 .net方向培训比较好的机构有哪些?求解 推荐几本关于C#的经典书籍,散分 求一查询sql C#怎样生成DLL文件? 关于窗体调用。。。。谢谢 .net下,怎么导入包呀? vs2008开发的c#代码可以编译成机器码吗? 一般的外网访问内网是怎么实现的?自己编写这个程序有没有可能? 简单的问题 用installutil卸载service不成功 (c#+ORACLE)客户端连接服务器端,软件连接失败!!
{
HttpFileCollection objFiles = HttpContext.Current.Request.Files;
HttpPostedFile objPostedFile = objFiles[0];
strOrgFileName = System.IO.Path.GetFileName(objPostedFile.FileName);
strFileExtension = System.IO.Path.GetExtension(strOrgFileName);
strCurFileName = Guid.NewGuid().ToString()+strFileExtension;
objPostedFile.SaveAs(Server.MapPath("../Upload/CustPic/") + strCurFileName);
}
private void Upload()
{
if(txtPhoto.Value != "")
{
string sFileName = txtPhoto.PostedFile.FileName;
string strFileExt = System.IO.Path.GetExtension(sFileName).ToString();
int nFileLength = Convert.ToInt32(txtPhoto.PostedFile.ContentLength.ToString());
string sUpPath = Server.MapPath("RESUMEPHOTO");
string sNewName = GetPhotoName();
//郪傖奻換腔俇淕繚噤
sUpPath += "\\" + sNewName;
//瓚剿垀猁奻換腔恅璃跡宒岆祥岆珨跺磁楊腔恅璃跡宒
if(!sNewName.Equals("Error") && nFileLength < 1024 *50)
{
txtPhoto.PostedFile.SaveAs(sUpPath);
}
else
{
Session["Messages"] ="恅璃跡宒[gif,jpg,jpeg,png]麼恅璃湮衾50K";
Response.Redirect("../Error.aspx");
} }
}
runat="server">
name="File1" runat="server">
按钮:
<asp:button id="cmdSubmit" runat="server" CssClass="redButtonCss" Width="60px" Text="发布" Height="20px"></asp:button>
我想上传word或excel文档,请问程序应当个怎么写?由于初学,望大家多多帮助,代码最好有注释。谢谢!
HttpPostedFile hpfFile = AttachFile.PostedFile;
if(hpfFile.FileName!="")
{
//有附件,则上传到Temp目录中
//取得文件名(不含路径)
char[] de = {'\\'};
string[] AFilename = hpfFile.FileName.Split(de);
string strFilename = AFilename[AFilename.Length-1];
string strPath = Server.MapPath(".")+"\\Temp\\"+strFilename;
hpfFile.SaveAs(strPath);
//添加附件
MyMsg.Attachments.Add(new MailAttachment(strPath));