private void UploadSkin(HttpContext context) { if (context.Request.Files.Count == 0) { log.Info("No files posted so returning 404"); context.Response.StatusCode = 404; return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { context.Response.StatusCode = 404; return; } if ((!WebUser.IsInRoles(siteSettings.RolesThatCanManageSkins))) { context.Response.StatusCode = 404; return; } bool overwriteFiles = true; if (context.Request.Params["frmData"] != null) { if (context.Request.Params["frmData"] == "off") { overwriteFiles = false; } } string destFolder = SiteUtils.GetSiteSystemFolder(); DirectoryInfo di = new DirectoryInfo(destFolder); if (!di.Exists) { di.Create(); } context.Response.ContentType = "text/plain";//"application/json"; var r = new List<UploadFilesResult>(); JavaScriptSerializer js = new JavaScriptSerializer(); for (int f = 0; f < context.Request.Files.Count; f++) { HttpPostedFile file = context.Request.Files[f]; string ext = System.IO.Path.GetExtension(file.FileName).ToLower().Replace(".",string.Empty); if (ext == "zip") { string destPath = Path.Combine(destFolder, Path.GetFileName(file.FileName).ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles)); if (File.Exists(destPath)) { File.Delete(destPath); } file.SaveAs(destPath); // process the .zip, extract files mojoPortal.Web.Components.SkinHelper helper = new mojoPortal.Web.Components.SkinHelper(); helper.InstallSkins(SiteUtils.GetSiteSkinFolderPath(), destPath, overwriteFiles); // delete the temporary file File.Delete(destPath); r.Add(new UploadFilesResult() { //Thumbnail_url = Name = file.FileName, Length = file.ContentLength, Type = file.ContentType }); } } var uploadedFiles = new { files = r.ToArray() }; var jsonObj = js.Serialize(uploadedFiles); context.Response.Write(jsonObj.ToString()); }
private void UploadSkin(HttpContext context) { if (context.Request.Files.Count == 0) { log.Info("No files posted so returning 404"); context.Response.StatusCode = 404; return; } SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); if (siteSettings == null) { context.Response.StatusCode = 404; return; } if ((!WebUser.IsInRoles(siteSettings.RolesThatCanManageSkins))) { context.Response.StatusCode = 404; return; } bool overwriteFiles = true; if (context.Request.Params["frmData"] != null) { if (context.Request.Params["frmData"] == "off") { overwriteFiles = false; } } string destFolder = SiteUtils.GetSiteSystemFolder(); DirectoryInfo di = new DirectoryInfo(destFolder); if (!di.Exists) { di.Create(); } context.Response.ContentType = "text/plain";//"application/json"; var r = new List <UploadFilesResult>(); JavaScriptSerializer js = new JavaScriptSerializer(); for (int f = 0; f < context.Request.Files.Count; f++) { HttpPostedFile file = context.Request.Files[f]; string ext = System.IO.Path.GetExtension(file.FileName).ToLower().Replace(".", string.Empty); if (ext == "zip") { string destPath = Path.Combine(destFolder, Path.GetFileName(file.FileName).ToCleanFileName(WebConfigSettings.ForceLowerCaseForUploadedFiles)); if (File.Exists(destPath)) { File.Delete(destPath); } file.SaveAs(destPath); // process the .zip, extract files mojoPortal.Web.Components.SkinHelper helper = new mojoPortal.Web.Components.SkinHelper(); helper.InstallSkins(SiteUtils.GetSiteSkinFolderPath(), destPath, overwriteFiles); // delete the temporary file File.Delete(destPath); r.Add(new UploadFilesResult() { //Thumbnail_url = Name = file.FileName, Length = file.ContentLength, Type = file.ContentType }); } } var uploadedFiles = new { files = r.ToArray() }; var jsonObj = js.Serialize(uploadedFiles); context.Response.Write(jsonObj.ToString()); }