public void Delete(HttpServerUtilityBase server, Image img) { try { System.IO.File.Delete(server.MapPath(img.Large)); } catch {} try { System.IO.File.Delete(server.MapPath(img.Medium)); } catch {} try { System.IO.File.Delete(server.MapPath(img.Thumb)); } catch {} Repo.Delete(img); }
public Image SaveImage(HttpServerUtilityBase server, HttpPostedFileBase file) { string largeUploadFolder = server.MapPath("~/assets/images/large"); string mediumUploadFolder = server.MapPath("~/assets/images/medium"); string thumbUploadFolder = server.MapPath("~/assets/images/thumb"); if (!Directory.Exists(largeUploadFolder)) Directory.CreateDirectory(largeUploadFolder); if (!Directory.Exists(mediumUploadFolder)) Directory.CreateDirectory(mediumUploadFolder); if (!Directory.Exists(thumbUploadFolder)) Directory.CreateDirectory(thumbUploadFolder); //The resizing settings can specify any of 30 commands.. See http://imageresizing.net for details. ResizeSettings largeSettings = new ResizeSettings("maxwidth=800&maxheight=800"); ResizeSettings mediumSettings = new ResizeSettings("maxwidth=300&maxheight=300&scale=both"); ResizeSettings thumbSettings = new ResizeSettings("width=100&height=100&crop=auto"); //var uniqueName = System.Guid.NewGuid().ToString(); string uniqueName = PathUtils.RemoveExtension(file.FileName) + "_" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss"); string largeFilePath = Path.Combine(largeUploadFolder, uniqueName); string mediumFilePath = Path.Combine(mediumUploadFolder, uniqueName); string thumbFilePath = Path.Combine(thumbUploadFolder, uniqueName); //Let the image builder add the correct extension based on the output file type (which may differ). var large = ImageBuilder.Current.Build(file, largeFilePath, largeSettings, false, true); var med = ImageBuilder.Current.Build(file, mediumFilePath, mediumSettings, false, true); var thumb = ImageBuilder.Current.Build(file, thumbFilePath, thumbSettings, false, true); Image img = new Image(PathUtils.RemoveExtension(file.FileName), ResolveRelativePath(server, large), ResolveRelativePath(server, med), ResolveRelativePath(server, thumb)); Repo.Save(img); return img; }
public Boolean delete_mvc_use_only(int id, HttpServerUtilityBase server_context) { try { HinhAnh kq = this.get_by_id(id); if (kq == null) return false; //first delete file try { String directory = "~/_Upload/HinhAnh/"; System.IO.File.Delete(server_context.MapPath(Path.Combine(directory, kq.duongdan))); System.IO.File.Delete(server_context.MapPath(Path.Combine(directory, kq.duongdan_thumb))); } catch (Exception ex) { Debug.WriteLine("qqqqqqqqqqqq"+ex.ToString()); } //delete in database _db.ds_hinhanh.Remove(kq); _db.SaveChanges(); return true; } catch (Exception ex) { Debug.WriteLine(ex.ToString()); return false; } }
public PRCImageCollection(HttpServerUtilityBase Server, string PRCRef) { this.PRCRef = PRCRef; this.ServerPath = new DirectoryInfo(Server.MapPath(@"~\")); this.CarouselImagesDirectoryPath = new DirectoryInfo(this.ServerPath + "CarouselImages\\" + PRCRef); this.PropertyImagesDirectoryPath = new DirectoryInfo(this.ServerPath + "PropertyImages\\" + PRCRef); //get all directories and files and create PRCImages GetAllImagesFromADirectoryAndPlaceInACollection(CarouselImagesDirectoryPath, CarouselImageList, this.CarouselImagesExists); GetAllImagesFromADirectoryAndPlaceInACollection(PropertyImagesDirectoryPath, PropertyImageList, this.PropertyImagesExists); if (CarouselImageList.Count > 0) { CarouselImagesExists = true; foreach (var image in CarouselImageList) { image.CapitalizeCamelCasedString(); } } if (PropertyImageList.Count > 0) { PropertyImagesExists = true; foreach (var image in PropertyImageList) { image.CapitalizeCamelCasedString(); } } }
internal Firma SwtorzFirme(HttpServerUtilityBase server, HttpPostedFileBase uploadFile) { string url = string.Empty; if (uploadFile != null && uploadFile.FileName != string.Empty) { url = Path.Combine(server.MapPath("~/Images/firmy"), uploadFile.FileName); uploadFile.SaveAs(url); url = Path.Combine("../Images/firmy", uploadFile.FileName); } Firma firma = new Firma { nazwa = nazwa, zdjecie = url, adres = new Adres { ulica = ulica, numer_budynku = numer_budynku, numer_lokalu = numer_lokalu, }, kontakt = new Kontakt { mail = mail, numer_komurkowy = numer_komurkowy }, }; return firma; }
public string CreateUserFolder(System.Web.HttpServerUtilityBase server) { var virtualPath = Path.Combine(rootFolder, Path.Combine("Upload", UserID), prettyName); var path = server.MapPath(virtualPath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); foreach (var sourceFolder in foldersToCopy) { CopyFolder(server.MapPath(sourceFolder), path); } } return(virtualPath); }
private static string SetCleanExtractFolder(HttpServerUtilityBase server, string mapPath, string cleanFileNameNoExtension) { var extractFolder = server.MapPath(mapPath + cleanFileNameNoExtension); MakeOrResetDirectory(extractFolder); return extractFolder; }
private static string GetEntryPoint(HttpServerUtilityBase server, string filePath, string root) { var fileName = PathHelpers.GetExactFilePath(filePath); var folder = server.MapPath(root); return PathHelpers.GetRequireRelativePath(folder, fileName); }
private static string ResolveRelativePath(HttpServerUtilityBase server, string physicalPath) { //C:\@Projects\Tarts\Tarts.Web\assets\images\large\1040c396-c558-473e-a3ca-f20de6ab13d2.jpg string relative = "~/assets/images"; string physical = server.MapPath(relative); return physicalPath.Replace(physical, relative).Replace("\\", "/").Replace("~",""); }
public static void Init(HttpServerUtilityBase server) { if (Current == null) { _filePath = server.MapPath("~/App_Data/Settings.xml"); Current = GetConnexion(); } }
public static ImageMetadata GetImageMetadata(HttpServerUtilityBase server, string imageUrl) { string path = server.MapPath(imageUrl + ".meta"); using (var reader = new StreamReader(path)) { return new ImageMetadata(imageUrl, reader); } }
/// <summary> /// Elimina un album e tutto il suo contenuto /// </summary> /// <param name="Server">Server object per MapPath</param> /// <param name="name">Nome dell'album (e nome cartella)</param> public static void Del(HttpServerUtilityBase Server, string name) { string path = Server.MapPath(BASE_PATH + "/" + name); if (Directory.Exists(path)) { Directory.Delete(path, true); } }
public string Save(HttpServerUtilityBase server, HttpPostedFileBase file) { string path = "/Images/" + file.FileName; string fullPath = server.MapPath(path); file.SaveAs(fullPath); return path; }
public FileRepository(ISettingsProvider settingsProvider, HttpServerUtilityBase server) { root = settingsProvider.GetSettings<Settings.FunnelWebSettings>().UploadPath; // If it's a virtual path then we can map it, otherwise we'll expect that it's a windows path if (root.StartsWith("~")) { root = server.MapPath(root); } }
static string DebugVirtualPath(string filename, HttpServerUtilityBase server) { return String.Format("/{0}", filename); // Use query string to break caching. This means the file's path // still matches the development file system. var absoluteFilename = server.MapPath("~/" + filename); var version = File.GetLastWriteTime(absoluteFilename).Ticks.ToString(); return String.Format("/static/{0}./{1}", version, filename); }
static string DebugVirtualPath(string filename, HttpServerUtilityBase server) { // Use query string to break caching. This means the file's path // still matches the development file system. var absoluteFilename = server.MapPath("~/static/" + filename); var version = File.GetLastWriteTime(absoluteFilename).Ticks.ToString(); var separator = (filename.Contains("?") ? "&" : "?"); return "/static/" + filename + separator + "nocache=" + version; }
public static void DeleteAvatar(Guid id, HttpServerUtilityBase server) { string fileName = Path.GetFileName(id.ToString() + ".png"); string fullPath = Path.Combine(server.MapPath("~/Data/Avatars"), fileName); FileInfo fileInfo = new FileInfo(fullPath); if (fileInfo.Exists) { fileInfo.Delete(); } }
/// <summary> /// 得到上传文件目录 /// </summary> /// <param name="applicationPath">应用程序路径</param> /// <param name="server">web请求服务</param> /// <param name="isOpen">是否需要对外开放,默认true</param> /// <returns>上传文件目录</returns> public static string CheckFileUpLoadDirectory(string applicationPath, System.Web.HttpServerUtilityBase server, UploadFileType type = UploadFileType.File) { string dic = server.MapPath(applicationPath + "/UploadFile/" + GetFileUpLoadPath(type)); if (!Directory.Exists(dic)) { Directory.CreateDirectory(dic); } return(dic); }
public static MvcHtmlString Menu(this HtmlHelper helper) { server = helper.ViewContext.RequestContext.HttpContext.Server; request = helper.ViewContext.RequestContext.HttpContext.Request; urlHelper = new UrlHelper(helper.ViewContext.RequestContext); routeDictionary = helper.ViewContext.RequestContext.RouteData.Values; HtmlHelper htmlHelper = new HtmlHelper(helper.ViewContext, helper.ViewDataContainer); //获取当前用户信息 //TalentMISDbContext db = new TalentMISDbContext(); //string current_account = helper.ViewContext.RequestContext.HttpContext.User.Identity.Name; //Account account = db.Accounts.FirstOrDefault(x => x.UserName.Trim().ToUpper() == current_account.Trim().ToUpper()); //string roleCode = account.RoleCode; string roleCode = ((CurrentUser)helper.ViewContext.RequestContext.HttpContext.Session["CurrentUser"]).RoleCode; //加载菜单xml文件 //string xmlPath = server.MapPath(url.Content("~/Menu.xml"));//当禁用Cookie时会话标识会嵌入URL中,此时该行代码结果就不正确了!(夏春涛) string webRootPath = server.MapPath("/"); string xmlPath = webRootPath.TrimEnd('\\') + "\\Menu.xml"; XDocument doc = XDocument.Load(xmlPath); var xmlNav = doc.Root; //获取所有符合条件的一级菜单(其中包括所有二级菜单) var nav1Items = xmlNav .Elements("NavItem") .Where(p => p.Attribute("roles").Value.Trim() == "" || p.Attribute("roles").Value.Trim().ToUpper().Contains(roleCode.ToUpper())); foreach (var nav1 in nav1Items) { //删除一级菜单下不符合条件的二级菜单 var nav2List = nav1.Elements("NavItem").ToList(); foreach (var nav2 in nav2List) { if (nav2.Attribute("roles").Value.Trim() == "")//任意角色均可访问的二级菜单 { continue; } bool isPermitted = nav2.Attribute("roles").Value.ToUpper().Contains(roleCode.Trim().ToUpper()); if (!isPermitted)//用户角色不再许可范围内 { nav1.Elements("NavItem") .Where(p => p.Attribute("code").Value.Trim().ToUpper() == nav2.Attribute("code").Value.Trim().ToUpper()) .Remove(); } } } //如果一级菜单下面没有二级菜单,则删除该一级菜单 nav1Items.Where(p => p.Elements().Count() == 0).Remove(); //---- MvcHtmlString result = htmlHelper.Partial("Menu", nav1Items); return result; }
public IEnumerable<string> GetAllImages(HttpServerUtilityBase server) { if (server != null) { var files = Directory.GetFiles(server.MapPath("~/Images/")); return files.Select(file => "/Images/" + Path.GetFileName(file)).ToArray(); } return new string[0]; }
protected void DeleteImage(string virtualPath, HttpServerUtilityBase server) { if (virtualPath != null) { string path = server.MapPath("~") + virtualPath; var file = new FileInfo(path); if (file.Exists) { file.Delete(); } } }
public static async Task DeleteRecord(this AppDbContext context, int id, HttpServerUtilityBase server) { var record = await context.Records.FindAsync(id); var path = server.MapPath(record.FilePath); if (File.Exists(path)) { File.Delete(path); } context.Records.Remove(record); await context.SaveChangesAsync(); }
public static String GuardarFicheroDisco(HttpPostedFileBase fichero,HttpServerUtilityBase server) { var id=Guid.NewGuid(); String nombre = null; if (fichero != null && fichero.ContentLength > 0) { var ext = fichero.FileName.Substring(fichero.FileName.LastIndexOf(".") + 1); nombre = $"{id}.{ext}"; fichero.SaveAs(server.MapPath("/ficheros")+"/"+nombre); } return nombre; }
public static void CreateClientFolders(this Client client, string applicationPath, HttpServerUtilityBase server) { if (client == null) { throw new ArgumentNullException("client"); } if (server == null) { throw new ArgumentNullException("server"); } string path = server.MapPath(client.ClientVirtualDirectoryToMap(applicationPath)); CreateClientFolders(path); }
public ImageRepository(HttpServerUtilityBase server, IDirectoryService directory, string rootPath) { string path = server.MapPath(rootPath); var files = directory.EnumerateFiles(path, "*.jpg"); foreach (var file in files) { string imageUrl = VirtualPathUtility.Combine(VirtualPathUtility.AppendTrailingSlash(rootPath), Path.GetFileName(file)); string metaPath = file + ".meta"; using (var reader = directory.GetReader(metaPath)) { _images.Add(new ImageMetadata(imageUrl, reader)); } } }
//le paso dos objetos el ifchero y la ruta que es el server public static String GuardarFicheroDisco(HttpPostedFileBase fichero,HttpServerUtilityBase server) { var id=Guid.NewGuid();// guid es un identificador unico para ponerle un nombre unico al fichero //var n = DateTime.Now.Ticks; coje la firma horaria del servidor es otra forma de nombrar unicamente al fichero String nombre = null; if (fichero!=null && fichero.ContentLength>0) { var ext = fichero.FileName.Substring(fichero.FileName.LastIndexOf(".") + 1);//Con esto tengo la extension del fichero para no tener problemas a la hora de abrir los ficheros nombre = $"{id}.{ext}";//unes la extensión al nombre del fichero fichero.SaveAs(server.MapPath("/ficheros")+"/"+nombre);//guarda el fichero en esa ruta del disco duro del servidor } return nombre; }
public ExtrasImage(HttpServerUtilityBase Server, string extraLegacyReference, string imageDirectory) { BookingExtraID = 0; ExtraLegacyReference = extraLegacyReference; FullImageName = ""; ImageFullFilePath = ""; ImageDescription = ""; ImageDirectory = ""; IsMainImage = false; ServerPath = new DirectoryInfo(Server.MapPath(@"~\")); ImagesDirectoryPath = new DirectoryInfo(this.ServerPath + "ExtraImages\\" + extraLegacyReference); }
internal SkinTranslations(HttpServerUtilityBase serverUtility, string skin, CultureInfo culture) { string path = serverUtility.MapPath(String.Format("~/Skins/{0}/config/translations.{1}.ini", skin, culture.TwoLetterISOLanguageName)); while (!File.Exists(path) && culture.Parent != null && culture.Parent != culture) { culture = culture.Parent; path = serverUtility.MapPath(String.Format("~/Skins/{0}/config/translations.{1}.ini", skin, culture.TwoLetterISOLanguageName)); } if (File.Exists(path)) { var iniFile = new IniFile(path); var sections = iniFile.GetSections(); if (sections.ContainsKey(SECTION_NAME)) { translations = iniFile.GetSection(SECTION_NAME); return; } Log.Error("Translation file {0} doesn't contain required section {1}", path, SECTION_NAME); } translations = new Dictionary<string, string>(); }
public AlbumModel(HttpServerUtilityBase Server, string Name) { if (!ExistsAlbum(Server)) throw new Exception("No Albums!"); if (Name == null) { string fullDir = Directory.GetDirectories(Server.MapPath(BASE_PATH))[0]; Name = (new DirectoryInfo(fullDir)).Name; } this.Name=Name; this.Path = Server.MapPath(BASE_PATH + "/" + Name); Imgs = new List<ImageModel>(); if (Directory.Exists(Path)) { foreach (string file in Directory.GetFiles(Path, "*.jpg")) { string appPath = Server.MapPath("~"); string fileUrl = string.Format("{0}", file.Replace(appPath, "").Replace("\\", "/")); Imgs.Add(new ImageModel(Name, file, fileUrl)); } } }
public static byte[] GetPhotoPreviewBuff(HttpServerUtilityBase server) { _LastAccessUTC = DateTime.UtcNow; StartTakingPhotoPreviewWorkerIfNotStarted(server); var buff = default(byte[]); lock (_syncBuff) { buff = _AvailableBuffNo == 1 ? _PhotoPreviewBuff1 : _PhotoPreviewBuff2; } if (buff == null) { return System.IO.File.ReadAllBytes(server.MapPath("~/App_Data/_blank.png")); } return buff; }
public void SaveFile(AdminUploadViewModel model, HttpServerUtilityBase server, int adminId, KnowledgeChannelEntities db) { var file = model.Resource.ResourceFile; if (file.ContentLength > 0) { var admin = db.Teachers.Where(x => x.TeacherID == adminId).SingleOrDefault(); var fileName = Path.GetFileName(file.FileName); var folderName = Path.Combine(server.MapPath("~/FileResources"), "KnowledgeChannel"); var folderNameTosave = Path.Combine("FileResources", "KnowledgeChannel"); if (!Directory.Exists(folderName)) { Directory.CreateDirectory(folderName); } var pathFileServer = Path.Combine(folderName, fileName); file.SaveAs(pathFileServer); var pathDatabase = Path.Combine(folderNameTosave, fileName); SaveInDatabase(model, pathDatabase, adminId, db); } }
private string ResizeSaveImage(int fileIndex, int width, int height, string oldImageName, int categoryid, HttpRequestBase requestFile, HttpServerUtilityBase server, HttpContextBase httpContext) { string imageName = ""; string salt = GenerateSalt(); ImageFormat format = GetImageFormat(requestFile.Files[fileIndex].FileName); byte[] firstImageBytes = GetResizedImage(requestFile.Files[fileIndex].InputStream, format, width, height); string firstImagePath = server.MapPath("~/Images/" + categoryid + "_" + salt + "_" + width + "X" + height + "_" + System.IO.Path.GetFileName(requestFile.Files[fileIndex].FileName)); System.IO.File.WriteAllBytes(firstImagePath, firstImageBytes); //delete old image file if (oldImageName != null) { string fileToDelete = httpContext.Server.MapPath("~") + oldImageName.Replace("~", ""); System.IO.File.Delete(fileToDelete); } return imageName = "~\\Images\\" + categoryid + "_" + salt + "_" + width + "X" + height + "_" + System.IO.Path.GetFileName(requestFile.Files[fileIndex].FileName); }
/// <summary> /// 得到照片上传文件目录 /// </summary> /// <param name="applicationPath">应用程序路径</param> /// <param name="server">web请求服务</param> /// <param name="uploadPath">要上传的目录 </param> /// <returns>返回值 照片上传文件目录</returns> public static string CheckPicUpLoadDirectory(string applicationPath, System.Web.HttpServerUtilityBase server, string uploadPath) { string dic = server.MapPath(applicationPath + uploadPath); return(CreateFilePath(dic)); }