コード例 #1
0
        public string Upload()
        {
            string status = "";

            if (HttpContext.Current.Request.Files.AllKeys.Any())
            {
                // Get the uploaded image from the Files collection
                var    httpPostedFile = HttpContext.Current.Request.Files["file"];
                string keyID          = HttpContext.Current.Request.Form["KeyID"];
                string UploadedBy     = HttpContext.Current.Request.Form["UploadedBy"];
                UploadedBy = UploadedBy.Trim('"');
                string Description      = HttpContext.Current.Request.Form["Description"];
                string rootpath         = ConfigurationManager.AppSettings["ViewpointUploadRootPath"];
                string uploadPath       = ConfigurationManager.AppSettings["UploadPath"];
                string completepath     = @rootpath + uploadPath;
                string upload_directory = DateTime.Now.Month.ToString("00") + "-" + DateTime.Now.Year.ToString();
                CreateIfMissing(completepath + upload_directory);

                if (httpPostedFile != null)
                {
                    // Get the complete file path
                    String fileSavePath = @completepath + upload_directory + @"\" + httpPostedFile.FileName.ToString();

                    // Save the uploaded file to "UploadedFiles" folder
                    httpPostedFile.SaveAs(fileSavePath);
                    DSL obj = new DSL();
                    status = obj.insertAttachmentViewpoint(keyID, "From Transit: " + Description, completepath + upload_directory + "\\" + httpPostedFile.FileName.ToString(), httpPostedFile.FileName.ToString(), UploadedBy);
                }
            }
            return(status);
        }