本文整理匯總了C#中AjaxControlToolkit.SaveAs方法的典型用法代碼示例。如果您正苦於以下問題:C# AjaxControlToolkit.SaveAs方法的具體用法?C# AjaxControlToolkit.SaveAs怎麽用?C# AjaxControlToolkit.SaveAs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類AjaxControlToolkit
的用法示例。
在下文中一共展示了AjaxControlToolkit.SaveAs方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetDataTableFromExcel
public static System.Data.DataTable GetDataTableFromExcel(AjaxControlToolkit.AsyncFileUpload pfileUpload, String puploadFolder, String psheetName, String pfileID)
{
System.Data.DataTable retval = null;
try
{
if (pfileUpload.HasFile)
{
string userSOEID = GetSOEID();
String _path = String.Empty;
String _fileName = String.Empty;
_fileName = pfileUpload.FileName;
//Save file
String uploadFolder = GetAppSetting("Upload_Folder");
uploadFolder += puploadFolder;
_path = System.Web.HttpContext.Current.Server.MapPath(uploadFolder);
_path = _path + pfileID + "_" + _fileName;
pfileUpload.SaveAs(_path);
string strConn = null;
strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + _path + ";Extended Properties=Excel 12.0;";
using (System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn))
{
conn.Open();
using (System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("SELECT * FROM [" + psheetName + "$]", conn))
{
cmd.CommandType = System.Data.CommandType.Text;
using (System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(cmd))
{
retval = new System.Data.DataTable();
da.Fill(retval);
}
}
conn.Close();
}
}
else
{
System.Web.HttpContext.Current.Session["uploadMessage"] = "UploadError: No file";
}
}
catch (UtilException uEx)
{
if (uEx.OriginalException.ToString().Contains("user-defined table type requires 77 column"))
{
System.Web.HttpContext.Current.Session["uploadMessage"] = "UploadError: The Sheet in the excel must be have 77 columns (ID, DepartmentID, Department, Process, Group, Activity, RecoverableTCD, OwnerSOEID, OwnerName, OwnerWorkPhone, OwnerHomePhone, OwnerAlternatePhone, OwnerEmail, BackupSOEID, BackupName, BackupWorkPhone, BackupHomePhone, BackupAlternatePhone, BackupEmail, BackupCenter, TCDSOEID, TCDName, TCDWorkPhone, TCDHomePhone, TCDAlternatePhone, TCDEmail, TCDCenter, GPLSOEID, GPLName, GPLWorkPhone, GPLHomePhone, GPLAlternatePhone, GPLEmail, GPLCenter, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec, BD-14, BD-13, BD-12, BD-11, BD-10, BD-9, BD-8, BD-7, BD-6, BD-5, BD-4, BD-3, BD-2, BD-1, BD1, BD2, BD3, BD4, BD5, BD6, BD7, BD8, BD9, BD10, BD11, BD12, BD13, BD14, BD15, BD16, BD17, BD18, BD19, BD20, BD21, DocumentLink), please review witch columns are missing in your file.";
}
else
{
System.Web.HttpContext.Current.Session["uploadMessage"] = "Exception: " + uEx.OriginalException.ToString();
}
}
catch (Exception ex)
{
if (ex.ToString().Contains("'" + psheetName + "$' is not a valid name."))
{
System.Web.HttpContext.Current.Session["uploadMessage"] = "UploadError: The Sheet name in the excel must be '" + psheetName + "'.";
}
else
{
UtilException uEx = new UtilException(ex);
uEx.StackTrace.Add((System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name) + " : " + (System.Reflection.MethodBase.GetCurrentMethod().Name));
uEx.SoeidSession = GetSOEID();
uEx.SaveExceptionInBD();
System.Web.HttpContext.Current.Session["uploadMessage"] = "Exception: " + uEx.OriginalException.ToString();
}
}
return retval;
}