This article is mainly on the ASP.net upload execl file, loaded on the page display (sample code) was introduced, the need for friends can come to the reference, I hope to help you.
Code as follows: #region upload execl file protected void Button1_Click (object sender, EventArgs e) { if (fileupload1.hasfile) { & nbsp String newfilename = string. Empty; String errormess = UploadFile (FileUpload1, ". xls|. Xlsx ", 1024 * 5, Server.MapPath ("/report/socialapply/"), 1, out newfilename); if (string. IsNullOrEmpty (errormess)) { &NB Sp Label1.Text = "√ File upload success"; viewstate["uploadfile"] = "/report/socialapply/" + newfilename; try {&nbs P FileStream file = new fileStream (Server.MapPath viewstate["Uplo Adfile "] As String), FileMode.Open, Fi Leaccess.read, fileshare.readwrite); DataTable dt1 = FairHR.Util.XmlExcelReport.ReadExcel Todatatable (file, 0, 0); Viewstate.add ("Viewdt", DT1); Gridview1.datasource = viewstate["VIEWDT"] as Datata ble gridview1.databind (); file. Close (); //maticsOft. Common.MessageBox.ResponseScript (Page, "$.messager.alert" (' System hint ', ' Operation successful!) ', ' info '); Catch &N Bsp { M Aticsoft. Common.MessageBox.ResponseScript (Page, "$.messager.alert" (' System hint ', ' please upload execl file again ', ' warning '); } Else { &N Bsp Label1.Text = "x file upload failed"; { else & nbsp { Label1.Text = "x Please select upload file First"; } SCRIPTMANAGER.REgisterclientscriptblock (Page, this.) GetType (), "IdAlert1", "closeload ();", true); } #endregion #region uploading files ///<summary> Upload files ///</summary> ///<param name= "fu" > upload file </param> /// <param name= "type" > upload file type, such as. Jpg|. Gif|. bmp</param> ///<param name= "size" > Limit upload file size, Unit k</param> ///<param Name= "path" > upload path, need to use server.mappath</param> ///<param name= "NameType" >1 for automatic naming, 0 used formerly </ param> ///<returns></returns> public static string UploadFile (FileUpload fu, S Tring type, int size, string path, int nametype, out string newfilename) { NEWFI Lename = null; string erorr = null; int Size = Fu. postedfile.contentlength/1024; if (Size > size) { Erorr = "Upload file is too large ! "; return Erorr; } string Type = Fu. FileName; if (Type.indexof (".") = = 1) {Erorr = "Upload file type is wrong!" "; return Erorr; } Type = type.substring (Type.lastindexof (".")). ToUpper (); type = type. ToUpper (); if (type. IndexOf (type) = = 1) {Erorr = "Upload file type is wrong!" "; return Erorr; } string filename = ""; if (nametype = 1) { STR ing nowdate = DateTime.Now.ToString (); nowdate = nowdate. Replace (":", ""). Replace ("", ""). Replace ("-", ""). Trim (); Random r = new Random ();   int a = R.next (1000); filename = nowdate + a.tostring () + Type; newfilename = filename; } else { & nbsp filename = fu. FileName; if (System.IO.File.Exists (path + filename)) {Erorr = "This file name already exists!" "; return Erorr; } } FU. SaveAs (path + filename); return erorr;//error message returned, no error returned null { #endregion