文件上傳后臺(tái)和前臺(tái)代碼(文件下載也是)-創(chuàng)新互聯(lián)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class upload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
    {

    }
protected void btupload_Click(object sender, EventArgs e)
    {
if (FileUpload1.HasFile)
        {
string filecontentType = FileUpload1.PostedFile.ContentType;
if (filecontentType == "image/bmp" || filecontentType == "image/gif" || filecontentType == "image/pjpeg" || filecontentType == "image/jpeg")
            {
string name = FileUpload1.PostedFile.FileName;
                FileInfo file= new FileInfo(name);
string filename = file.Name;
string webFilePath = Server.MapPath("image/" + filename);
if (!File.Exists(webFilePath))
                {
try
                    {
                        FileUpload1.SaveAs(webFilePath);
this.lmsg.Text = "提示:文件" + filename + "上傳成功!";
this.lpathInfo.Text = "image/" + filename;
this.iPic.ImageUrl = "image/" + filename;
                    }
catch (Exception ex)
                    {
this.lmsg.Text = "提示文件上傳失敗,失敗原因" + ex.Message;

                    }
                }
else
                {
this.lmsg.Text = "該文件已經(jīng)存在!";
                }
            }
else {
this.lmsg.Text = "提示:文件類型不符";
            }
        }
    }
}
前臺(tái)代碼如下:文件上傳后臺(tái)和前臺(tái)代碼(文件下載
也是) <%@ Page Language="C#" AutoEventWireup="true" CodeFile="upload.aspx.cs" Inherits="upload" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td><asp:FileUpload ID="FileUpload1" runat="server" /> <asp:Button ID="btupload" runat="server" onclick="btupload_Click" Text="上傳" /> <asp:Image ID="iPic" ImageUrl="" Height="100px" runat="server" /> </td> </tr> <tr><td> <asp:Label ID="lmsg" runat="server" Text="Label"></asp:Label>      <asp:Label ID="lpathInfo" runat="server" Text="Label"></asp:Label> </td></tr> </table> </div> </form> </body> </html>

 文件下載代碼

創(chuàng)新互聯(lián)公司堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計(jì)、做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的黟縣網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

分享題目:文件上傳后臺(tái)和前臺(tái)代碼(文件下載也是)-創(chuàng)新互聯(lián)
地址分享:http://muchs.cn/article0/cspeio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、搜索引擎優(yōu)化手機(jī)網(wǎng)站建設(shè)、網(wǎng)站收錄、微信公眾號(hào)、品牌網(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)

綿陽(yáng)服務(wù)器托管