asp.net文件上傳并顯示文件名刪除文件重新上傳

          
前臺(tái)頁(yè)面:
<h3 class="mt20">活動(dòng)/宣傳信息</h3>
<table width="860"  class="info_tab3 ctabt" id="table2">
  <tr>
   <th width="15%">活動(dòng)名稱</th>
   <td><asp:TextBox ID="activityname"  size="78" runat="server"  TextName="活動(dòng)名稱" MaxLength="100" ></asp:TextBox><span class="title_red">*</span></td>
  </tr>
  <tr>
   <th>活動(dòng)概要</th>
    <td>
  
    <asp:TextBox ID="summary"  Width="420px"  runat="server" Height="55"    TextMode="MultiLine"  onpropertychange="MaxLength(this,300)"></asp:TextBox></td>
    </tr>
  <tr>
    <th>活動(dòng)時(shí)間段</th>
  
  <td> <asp:TextBox ID="time"  size="78" runat="server"  MaxLength="40" ></asp:TextBox></td>
  </tr>
  <tr>
    <th>活動(dòng)地區(qū)</th>
    <td><asp:TextBox ID="area"   Width="420px"  runat="server" Height="55"   TextMode="MultiLine" onpropertychange="MaxLength(this,300)"></asp:TextBox></td>
  </tr>
  <tr>
    <th>活動(dòng)地點(diǎn)</th>
   <td> <asp:TextBox ID="address"  size="78" runat="server" MaxLength="100" ></asp:TextBox></td>
  </tr>
  <tr>
    <th>宣傳媒體</th>
   <td><asp:TextBox ID="media"  size="78" runat="server" MaxLength="100" ></asp:TextBox></td>
  </tr>
</table>
 
<h3 class="mt20">上傳附件</h3>
<tr align="left">
<div class="boperation"  >
<center>
&nbsp;<asp:UpdatePanel ID="UpdatePanel1" runat="server" RenderMode="Block" UpdateMode="Conditional">
        <ContentTemplate>
            其他格式促銷資料:<asp:FileUpload ID="fuPhoto" runat="server" onchange="PreviewImg();"
                Width="300px" />
        </ContentTemplate>
 <Triggers>
 <asp:PostBackTrigger ControlID="delA" />
 </Triggers>
</asp:UpdatePanel>
<asp:HyperLink ID="filePath" runat="server" Target="_blank" Visible="false" ></asp:HyperLink>
<asp:LinkButton Visible="false" ID="delA" Text="[X]" runat="server" OnCommand="delA_Click"></asp:LinkButton>
<asp:HiddenField ID="fileUploadPath" runat="server" />
 
 <asp:UpdatePanel ID="UpdatePanelFileUpload" runat="server" RenderMode="Block" UpdateMode="Conditional">
 <Triggers>
 <asp:PostBackTrigger ControlID="lbUploadPhoto" />
 </Triggers>
</asp:UpdatePanel>
<asp:LinkButton ID="lbUploadPhoto" runat="server" Text="aa" OnClick="lbUpload_Click"></asp:LinkButton>
</center>
  </div>
 
 
后臺(tái)處理:
 //上傳附件
        protected void lbUpload_Click(object sender, EventArgs e)
        {
            fileUpload();
        }
        //刪除附件
        protected void delA_Click(object sender, CommandEventArgs e)
        {
            string path = fileUploadPath.Value;
            path = Server.MapPath(path);
            FileInfo file = new FileInfo(path);
            if (file.Exists)
            {
                file.Delete();
            }
            fileUploadPath.Value = "";
            fuPhoto.Visible = true;
            filePath.Visible = false;
            delA.Visible = false;
        }
        public void fileUpload()
        {
            if (fuPhoto.PostedFile != null && fuPhoto.PostedFile.ContentLength > 0)
            {
                string ext = System.IO.Path.GetExtension(fuPhoto.PostedFile.FileName).ToLower();
                //if (ext != ".jpg" && ext != ".jepg" && ext != ".bmp" && ext != ".gif" && ext != ".png")
                //{
                //    this.Alert("請(qǐng)上傳(*.jpg,*.jepg,*.bmp,*.gif,*.png)格式的圖片!");
                //    return;
                //}
                string dir = Server.MapPath(PRODUCE_TEMP_FILE_PATH);
                if (Directory.Exists(dir) == false)
                {
                    Directory.CreateDirectory(dir);
                }
                string filename = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ext;
                string path = PRODUCE_TEMP_FILE_PATH + filename;
                fuPhoto.PostedFile.SaveAs(Server.MapPath(path));
                fileUploadPath.Value = path;
                fuPhoto.Visible = false;
                delA.Visible = true;
                filePath.Visible = true;
                filePath.Text = fuPhoto.FileName;
                filePath.NavigateUrl = path;
                // uploadfilepath.Text = path;
            }
            else
            {
                //do some thing;
            }
        }
 
 
保存

            ProductSellPlanEntity sellplan = new ProductSellPlanEntity();
            sellplan.ResourceId = System.Guid.NewGuid().ToString();
            sellplan.ProjectId = productNum.Text;
            sellplan.CreateNumber = createNumber.Text;
            sellplan.ContantCompany = companyID.Value;
            sellplan.ProjectTime = projecttime.Text;
            sellplan.CreateUser = this.CurrentUser.UserName;
            sellplan.CreateUserID = CurrentUser.UserId;
            sellplan.Telphone = CurrentUser.OfficePhone;
            sellplan.ActivityName = activityname.Text;
            sellplan.ActivityDescription = summary.Text;
            sellplan.ActivityTime = time.Text;
            sellplan.ActivityArea = area.Text;
            sellplan.ActivityAddress = address.Text;
            sellplan.PropagandaMedia = media.Text;
            sellplan.UploadFilename = filePath.Text;
            if (!string.IsNullOrEmpty(fileUploadPath.Value))
            {
                string path = Server.MapPath(fileUploadPath.Value);
                FileInfo file = new FileInfo(path);
                if (file.Exists)
                {
                    string dir = Server.MapPath(PRODUCE_FILE_PATH);
                    if (Directory.Exists(dir) == false)
                    {
                        Directory.CreateDirectory(dir);
                    }
                    string fname = DateTime.Now.ToString("yyyyMMddHHmmssffff") + filePath.Text;
                    string targetFile = dir + fname;
                    if (path.IndexOf("ImportFiles") >= 0)
                    {
                        file.CopyTo(targetFile);
                    }
                    sellplan.UploadFilepath = PRODUCE_FILE_PATH + fname;
                }
                if (path.IndexOf("ImportFiles") >= 0)
                {
                    FileInfo filetemp = new FileInfo(path);
                    filetemp.Delete();
                }
            }
 
 
 
效果圖片:asp.net文件上傳并顯示文件名刪除文件重新上傳

網(wǎng)站題目:asp.net文件上傳并顯示文件名刪除文件重新上傳
URL鏈接:http://muchs.cn/article6/ghecog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號(hào)、手機(jī)網(wǎng)站建設(shè)、搜索引擎優(yōu)化、營(yíng)銷型網(wǎng)站建設(shè)面包屑導(dǎo)航、移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都網(wǎng)頁(yè)設(shè)計(jì)公司