當前位置: 首頁>>代碼示例>>C#>>正文


C# venuesEntities.AddTotbl_file方法代碼示例

本文整理匯總了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);
                }

            }
        }
開發者ID:zyyecho,項目名稱:venues,代碼行數:43,代碼來源:FileService.aspx.cs


注:本文中的WebService.venuesEntities.AddTotbl_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。