亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

ASP.NET - FileUpload Web 服務器控件概述(下)

2019-11-17 04:01:50
字體:
來源:轉載
供稿:網友
示例

第一個示例演示如何創建 FileUpload 控件,該控件將文件保存到代碼中指定的路徑。

<%@ Page Language="C#" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<script runat="server">



  PRotected void UploadButton_Click(object sender, EventArgs e)

  {

    // Specify the path on the server to

    // save the uploaded file to.

    String savePath = @"c:/temp/uploads/";



    // Before attempting to perform Operations

    // on the file, verify that the FileUpload

    // control contains a file.

    if (FileUpload1.HasFile)

    {

      // Get the name of the file to upload.

      String fileName = FileUpload1.FileName;



      // Append the name of the file to upload to the path.

      savePath += fileName;





      // Call the SaveAs method to save the

      // uploaded file to the specified path.

      // This example does not perform all

      // the necessary error checking.               

      // If a file with the same name

      // already exists in the specified path,  

      // the uploaded file overwrites it.

      FileUpload1.SaveAs(savePath);



      // Notify the user of the name of the file

      // was saved under.

      UploadStatusLabel.Text = "Your file was saved as " + fileName;

    }

    else

    {      

      // Notify the user that a file was not uploaded.

      UploadStatusLabel.Text = "You did not specify a file to upload.";

    }



  }

</script>



<html  >

<head runat="server">

    <title>FileUpload Example</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

       <h4>Select a file to upload:</h4>



       <asp:FileUpload id="FileUpload1"                 

           runat="server">

       </asp:FileUpload>



       <br /><br />



       <asp:Button id="UploadButton"

           Text="Upload file"

           OnClick="UploadButton_Click"

           runat="server">

       </asp:Button>    



       <hr />



       <asp:Label id="UploadStatusLabel"

           runat="server">

       </asp:Label>        

    </div>

    </form>

</body>

</html>



      第二個示例演示如何創建 FileUpload 控件,該控件將文件保存到文件系統中針對應用程序的指定目錄。

<%@ Page Language="C#" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<script runat="server">



    protected void UploadButton_Click(object sender, EventArgs e)

    {

        // Save the uploaded file to an "Uploads" directory

        // that already exists in the file system of the

        // currently executing asp.net application.  

        // Creating an "Uploads" directory isolates uploaded

        // files in a separate directory. This helps prevent

        // users from overwriting existing application files by

        // uploading files with names like "Web.config".

        string saveDir = @"/Uploads/";



        // Get the physical file system path for the currently

        // executing application.

        string appPath = Request.PhysicalApplicationPath;



        // Before attempting to save the file, verify

        // that the FileUpload control contains a file.

        if (FileUpload1.HasFile)

        {

            string savePath = appPath + saveDir +

                Server.HtmlEncode(FileUpload1.FileName);



            // Call the SaveAs method to save the

            // uploaded file to the specified path.

            // This example does not perform all

            // the necessary error checking.               

            // If a file with the same name

            // already exists in the specified path,  

            // the uploaded file overwrites it.

            FileUpload1.SaveAs(savePath);



            // Notify the user that the file was uploaded successfully.

            UploadStatusLabel.Text = "Your file was uploaded successfully.";



        }

        else

        {

            // Notify the user that a file was not uploaded.

            UploadStatusLabel.Text = "You did not specify a file to upload.";   

        }

    }

</script>



<html  >

<head runat="server">

    <title>FileUpload Class Example</title>

</head>

<body>

    <h3>FileUpload Class Example: Save To Application Directory</h3>

    <form id="form1" runat="server">

    <div>

       <h4>Select a file to upload:</h4>



       <asp:FileUpload id="FileUpload1"                 

           runat="server">

       </asp:FileUpload>



       <br/><br/>



       <asp:Button id="UploadButton"

           Text="Upload file"

           OnClick="UploadButton_Click"

           runat="server">

       </asp:Button>    



       <hr />



       <asp:Label id="UploadStatusLabel"

           runat="server">

       </asp:Label>           

    </div>

    </form>

</body>

</html>



      第三個示例演示如何創建 FileUpload 控件,該控件將文件保存到指定路徑并限制可以上載的文件的大小。

<%@ Page Language="C#" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<script runat="server">



    protected void UploadButton_Click(object sender, EventArgs e)

    {

        // Specify the path on the server to

        // save the uploaded file to.

        string savePath = @"c:/temp/uploads/";



        // Before attempting to save the file, verify

        // that the FileUpload control contains a file.

        if (FileUpload1.HasFile)

        {                

            // Get the size in bytes of the file to upload.

            int fileSize = FileUpload1.PostedFile.ContentLength;



            // Allow only files less than 2,100,000 bytes (approximately 2 MB) to be uploaded.

            if (fileSize < 2100000)

            {



                // Append the name of the uploaded file to the path.

                savePath += Server.HtmlEncode(FileUpload1.FileName);



                // Call the SaveAs method to save the

                // uploaded file to the specified path.

                // This example does not perform all

                // the necessary error checking.               

                // If a file with the same name

                // already exists in the specified path,  

                // the uploaded file overwrites it.

                FileUpload1.SaveAs(savePath);



                // Notify the user that the file was uploaded successfully.

                UploadStatusLabel.Text = "Your file was uploaded successfully.";

            }

            else

            {

                // Notify the user why their file was not uploaded.

                UploadStatusLabel.Text = "Your file was not uploaded because " +

                                         "it exceeds the 2 MB size limit.";

            }

        }   

        else

        {

            // Notify the user that a file was not uploaded.

            UploadStatusLabel.Text = "You did not specify a file to upload.";

        }

    }

</script>



<html  >

<head runat="server">

    <title>FileUpload Class Example</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

       <h4>Select a file to upload:</h4>



       <asp:FileUpload id="FileUpload1"                 

           runat="server">

       </asp:FileUpload>



       <br/><br/>



       <asp:Button id="UploadButton"

           Text="Upload file"

           OnClick="UploadButton_Click"

           runat="server">

       </asp:Button>



       <hr />



       <asp:Label id="UploadStatusLabel"

           runat="server">

       </asp:Label>



    </div>

    </form>

</body>

</html>



第四個示例演示如何創建 FileUpload 控件,該控件將文件保存到指定路徑并且只允許上載擴展名為 .doc 或 .xls 的文件。

<%@ Page Language="C#" %>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



<script runat="server">



    protected void UploadBtn_Click(object sender, EventArgs e)

    {

        // Specify the path on the server to

        // save the uploaded file to.

        string savePath = @"c:/temp/uploads";



        // Before attempting to save the file, verify

        // that the FileUpload control contains a file.

        if (FileUpload1.HasFile)

        {

            // Get the name of the file to upload.

            string fileName = Server.HtmlEncode(FileUpload1.FileName);



            // Get the extension of the uploaded file.

            string extension = System.IO.Path.GetExtension(fileName);



            // Allow only files with .doc or .xls extensions

            // to be uploaded.

            if ((extension == ".doc") | (extension == ".xls"))

            {

                // Append the name of the file to upload to the path.

                savePath += fileName;



                // Call the SaveAs method to save the

                // uploaded file to the specified path.

                // This example does not perform all

                // the necessary error checking.               

                // If a file with the same name

                // already exists in the specified path,  

                // the uploaded file overwrites it.

                FileUpload1.SaveAs(savePath);



                // Notify the user that their file was successfully uploaded.

                UploadStatusLabel.Text = "Your file was uploaded successfully.";

            }

            else

            {

                // Notify the user why their file was not uploaded.

                UploadStatusLabel.Text = "Your file was not uploaded because " +

                                         "it does not have a .doc or .xls extension.";

            }



        }



    }



</script>



<html  >

<head runat="server">

    <title>FileUpload Class Example</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <h4>Select a file to upload:</h4>



        <asp:FileUpload id="FileUpload1"                 

            runat="server">

        </asp:FileUpload>



        <br/><br/>



        <asp:Button id="UploadBtn"

            Text="Upload file"

            OnClick="UploadBtn_Click"

            runat="server">

        </asp:Button>    



        <hr />



        <asp:Label id="UploadStatusLabel"

            runat="server">

        </asp:Label>     

    </div>

    </form>

</body>

</html>
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
www高清在线视频日韩欧美| 精品爽片免费看久久| 欧美成aaa人片在线观看蜜臀| 亚洲www永久成人夜色| 26uuu另类亚洲欧美日本一| 亚洲国产精品大全| 日韩国产欧美精品在线| 91精品中国老女人| 欧洲s码亚洲m码精品一区| 久久影视电视剧免费网站| 日本三级久久久| 国产精品国产三级国产aⅴ9色| 亚洲天堂av电影| www亚洲欧美| 国产一区二区激情| 91亚洲精华国产精华| 久久亚洲精品中文字幕冲田杏梨| 91热精品视频| 久久精品小视频| 91豆花精品一区| 日韩网站免费观看| 日本久久久a级免费| 中文字幕亚洲专区| 欧美人交a欧美精品| 亚洲一区av在线播放| 中文字幕精品一区久久久久| 国产精品欧美激情| 亚洲无限乱码一二三四麻| 国产一区二区激情| 伊人久久大香线蕉av一区二区| 97超级碰碰碰久久久| 亚洲免费视频观看| 日韩在线观看免费网站| 久久青草精品视频免费观看| 九九热精品视频在线播放| 欧美日韩性生活视频| 欧美大片大片在线播放| 亚洲aaaaaa| 欧美成人免费全部观看天天性色| 国产精品久久久久久久久久99| 搡老女人一区二区三区视频tv| 亚洲免费av电影| 91国产视频在线播放| 神马久久久久久| 欧美中文字幕视频| 国模私拍视频一区| 最近2019中文字幕第三页视频| 欧美激情视频一区二区三区不卡| 亚洲天堂精品在线| 国产精品第二页| 精品国产91久久久久久老师| 国产精品成久久久久三级| 国外成人在线直播| 精品无人区乱码1区2区3区在线| 欧美午夜激情在线| 狠狠躁18三区二区一区| 91在线无精精品一区二区| 欧美亚洲在线播放| 亚洲高清免费观看高清完整版| 国产精品视频1区| 国产精品中文在线| 日韩中文字幕视频| 国产精品久久一区主播| 国产精品视频午夜| 成人久久18免费网站图片| 亚洲美女免费精品视频在线观看| 日韩欧美福利视频| 精品亚洲一区二区三区| 亚洲黄色有码视频| 精品视频在线观看日韩| 午夜精品视频网站| 啪一啪鲁一鲁2019在线视频| 国产精品久久久久一区二区| 国产成人综合精品| 国产精品久久久久久久久粉嫩av| 奇米成人av国产一区二区三区| 欧美成aaa人片免费看| 亚洲人成网站色ww在线| 久久伊人91精品综合网站| 久久久精品亚洲| 国产精品成人久久久久| 亚洲欧美在线免费| 成人午夜在线视频一区| 亚洲精品视频网上网址在线观看| 国产精品女主播视频| 亚洲成在人线av| 丝袜美腿亚洲一区二区| 97视频色精品| 久久精品亚洲国产| 欧美性猛交xxxxx免费看| 91精品视频播放| 91精品久久久久久久久不口人| 国产精品老女人视频| 国产精品自拍偷拍| 日韩欧美亚洲范冰冰与中字| 91午夜理伦私人影院| 精品久久久国产| 日本欧美在线视频| 色伦专区97中文字幕| 亚洲美女av在线| 中文字幕亚洲综合久久筱田步美| 97久久久久久| 富二代精品短视频| 成人高h视频在线| 欧美精品一区在线播放| 久久欧美在线电影| 精品欧美一区二区三区| 91亚洲一区精品| 国产+人+亚洲| 色av吧综合网| 亚洲一区二区在线| 亚洲成人黄色在线| 97色在线播放视频| 91久久久国产精品| 亚洲欧洲一区二区三区在线观看| 国产精品视频在线观看| 成人黄色生活片| 国产精品久久久久久久久久久久久久| 亚洲一区美女视频在线观看免费| 国产欧美精品日韩| 午夜精品一区二区三区av| 日韩欧美亚洲国产一区| 亚洲国产精品久久91精品| 亚洲自拍偷拍视频| 亚洲精品一区中文| 精品免费在线视频| 都市激情亚洲色图| 日韩最新中文字幕电影免费看| 亚洲国产精品推荐| 亚洲va欧美va在线观看| 久久久久久久av| 亚洲欧美中文在线视频| 亚洲福利在线观看| 精品激情国产视频| 日本高清视频精品| 亚洲精品国产精品久久清纯直播| 欧美日韩国产成人在线观看| 亚洲娇小xxxx欧美娇小| 中文字幕亚洲欧美日韩2019| 亚洲午夜小视频| 欧美—级高清免费播放| 久久躁日日躁aaaaxxxx| 日韩69视频在线观看| 久久精视频免费在线久久完整在线看| 色老头一区二区三区| 中文字幕在线观看亚洲| 亚洲欧美一区二区三区情侣bbw| 九九热这里只有精品免费看| 欧美激情亚洲视频| 日韩美女av在线| 美女国内精品自产拍在线播放| 欧美xxxx做受欧美.88| 欧美精品国产精品日韩精品| 亚洲精品一区在线观看香蕉| 国产福利精品av综合导导航| 懂色av影视一区二区三区| 国产视频精品va久久久久久| 欧美日本高清一区| 一本色道久久综合亚洲精品小说| 欧美日韩国产黄| 91香蕉嫩草影院入口| 午夜精品视频在线| 国产精品电影网| 91高清视频在线免费观看|