public static string SaveImageAsync(AsyncFileUpload Fu, string prefix, string localImagePath) { if (!Directory.Exists(localImagePath)) Directory.CreateDirectory(localImagePath); string strImage = string.Empty; string SavePath = string.Empty; //SavePath = GetImagePathWithFileName(3, prefix, localImagePath); SavePath = localImagePath; SavePath += '\\' + prefix; Fu.SaveAs(SavePath); Fu.FileContent.Dispose(); strImage = SavePath; //Fu.PostedFile.ContentLength return strImage; }
public static Guid UploadAttach(AsyncFileUpload fu) { if (!fu.HasFile || fu.FileName.Length == 0) { throw new BusinessObjectLogicException("Please select upload file!"); } string path = null; try { string subDirectory = DateTime.Now.ToString("yyyyMM") + Path.DirectorySeparatorChar + DateTime.Now.ToString("dd"); string directory = System.Configuration.ConfigurationManager.AppSettings["File"] + subDirectory; if (!Directory.Exists(directory)) Directory.CreateDirectory(directory); string title = Path.GetFileName(fu.FileName); string ext = Path.GetExtension(fu.FileName); path = Path.DirectorySeparatorChar + Path.GetRandomFileName() + ext; fu.SaveAs(directory + path); Attachment attach = new Attachment(UserHelper.UserName); attach.Title = title; attach.Path = subDirectory + path; new AttachmentBl().AddAttach(attach); return attach.UID; } catch { throw new BusinessObjectLogicException("File upload fail!"); } }