上传附件的问题,哪位能提供完整代码,在线等!!!!!

解决方案 »

  1.   

    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);
    }
      

  2.   

    /// </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");
    } }
    }
      

  3.   

    <input type="file" size="53" id="txtPhoto" class="InputTxt" name="txtPhoto" onmouseover="ShowPhoto();"
    runat="server">
      

  4.   

    <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文档,请问程序应当个怎么写?由于初学,望大家多多帮助,代码最好有注释。谢谢!
      

  5.   

    //如果有附件则上传
    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));