本文整理匯總了C#中WebService.venuesEntities.AddTotbl_file方法的典型用法代碼示例。如果您正苦於以下問題:C# venuesEntities.AddTotbl_file方法的具體用法?C# venuesEntities.AddTotbl_file怎麽用?C# venuesEntities.AddTotbl_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類WebService.venuesEntities
的用法示例。
在下文中一共展示了venuesEntities.AddTotbl_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string path = System.Configuration.ConfigurationManager.AppSettings["FilePath"].ToString()+"\\files";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
HttpFileCollection files = Request.Files;
if (files.Count == 0)
{
Response.Write("請勿直接訪問本文件");
Response.End();
}
// 隻取第 1 個文件
HttpPostedFile file = files[0];
if (file != null && file.ContentLength > 0)
{
using (venuesEntities db = new venuesEntities())
{
tbl_file kf = new tbl_file();
float m = (float)file.ContentLength / 1048576;
kf.Size =float.Parse( Math.Round(m,2).ToString());
kf.FileNameLocal = file.FileName;
string serverName = DateTime.Now.ToString("yyyyMMdd_HHmmss") + Path.GetExtension(Request.Form["fileName"]).ToLower();
kf.FileNameServer = "files/"+ serverName;
kf.FileUploadTime = DateTime.Now;
kf.FileUserID = int.Parse(Request.Params.Get("curUserID"));
kf.UserVenueTypeID = Request.Params.Get("curUserTypeParentID");
kf.Ext = System.IO.Path.GetExtension(file.FileName.ToLower()).Substring(1);
kf.DescribeInfo = Request.Params.Get("descript");
db.AddTotbl_file(kf);
db.SaveChanges();
string savePath = path + "\\" + serverName;
file.SaveAs(savePath);
}
}
}