private void FillViewSets() { ddlViewSets.Items.Clear(); var hostViewsDir = new DirectoryInfo(Server.MapPath(PathHelper.ViewsVirtualPath)); var hostViewSets = hostViewsDir.GetDirectories(); foreach (var hostViewSet in hostViewSets) { var item = new ListItem(); item.Text = string.Format(Localization.GetString("Host"), hostViewSet.Name); item.Value = VirtualPathUtility.Combine(PathHelper.ViewsVirtualPath, hostViewSet.Name); ddlViewSets.Items.Add(item); } var siteViewsPath = DnnPathHelper.GetViewsVirtualPath(); var siteViewsDir = new DirectoryInfo(Server.MapPath(siteViewsPath)); if (siteViewsDir.Exists) { var siteViewSets = siteViewsDir.GetDirectories(); foreach (var siteViewSet in siteViewSets) { var item = new ListItem(); item.Text = string.Format(Localization.GetString("Site"), siteViewSet.Name); item.Value = VirtualPathUtility.Combine(siteViewsPath, siteViewSet.Name); ddlViewSets.Items.Add(item); } } }
private void LoadSettings() { appRoot = WebUtils.GetApplicationRoot(); moduleSettings = ModuleSettings.GetModuleSettings(moduleId); config = new GalleryConfiguration(moduleSettings); lnkCancel.NavigateUrl = SiteUtils.GetCurrentPageUrl(); //if (WebConfigSettings.ImageGalleryUseMediaFolder) //{ imageFolderPath = "~/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/media/GalleryImages/" + moduleId.ToInvariantString() + "/"; thumbnailBaseUrl = ImageSiteRoot + "/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/media/GalleryImages/" + moduleId.ToInvariantString() + "/Thumbnails/"; //} //else //{ // imageFolderPath = "~/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/GalleryImages/" + moduleId.ToInvariantString() + "/"; // thumbnailBaseUrl = ImageSiteRoot + "/Data/Sites/" + siteSettings.SiteId.ToInvariantString() + "/GalleryImages/" + moduleId.ToInvariantString() + "/Thumbnails/"; //} fullSizeImageFolderPath = VirtualPathUtility.Combine(imageFolderPath, "FullSizeImages/"); edDescription.WebEditor.ToolBar = ToolBar.Full; AddClassToBody("galleryeditimage"); FileSystemProvider p = FileSystemManager.Providers[WebConfigSettings.FileSystemProvider]; if (p == null) { return; } fileSystem = p.GetFileSystem(); GalleryHelper.VerifyGalleryFolders(fileSystem, imageFolderPath); uploader.AcceptFileTypes = SecurityHelper.GetRegexValidationForAllowedExtensionsJqueryFileUploader(SiteUtils.ImageFileExtensions()); uploader.ServiceUrl = SiteRoot + "/ImageGallery/upload.ashx?pageid=" + pageId.ToInvariantString() + "&mid=" + moduleId.ToInvariantString() + "&ItemID=" + itemId.ToInvariantString(); // itemid will be returned into this field uploader.ReturnValueFormFieldClientId = hdnState.ClientID; uploader.FormFieldClientId = hdnState.ClientID; // not really used but prevents submitting all the form string refreshFunction = "function refresh" + moduleId.ToInvariantString() + " () { $('#" + btnUpdate.ClientID + "').click(); } "; uploader.UploadCompleteCallback = "refresh" + moduleId.ToInvariantString(); ScriptManager.RegisterClientScriptBlock( this, this.GetType(), "refresh" + moduleId.ToInvariantString(), refreshFunction, true); }
void btnNewFolder_Click(object sender, EventArgs e) { if (!canEdit) { return; } if ((hdnFolder.Value.Length > 0) && (hdnFolder.Value != rootDirectory)) { currentDir = hdnFolder.Value; } if (fileSystem.CountFolders() <= fileSystem.Permission.MaxFolders) { try { fileSystem.CreateFolder(VirtualPathUtility.Combine(GetCurrentDirectory(), Path.GetFileName(txtNewDirectory.Text).ToCleanFolderName(WebConfigSettings.ForceLowerCaseForFolderCreation))); txtNewDirectory.Text = ""; WebUtils.SetupRedirect(this, GetRedirectUrl()); } catch (UnauthorizedAccessException ex) { lblError.Text = ex.Message; } catch (ArgumentException ex) { lblError.Text = ex.Message; } } else { lblError.Text = Resource.FileSystemFolderLimitReached; } }
/// <summary> /// Moves a virtual directopry to a new location, optioanlly renaming it in the process. /// </summary> /// <param name="sourceDirectory">The source directory to be moved.</param> /// <param name="targetDirectory">The destination directory.</param> /// <param name="newName">An optional new name. Supply <c>null</c> to use the original name of the source file.</param> public static void MoveDirectory(VirtualDirectory sourceDirectory, UnifiedDirectory targetDirectory, string newName) { if (String.IsNullOrEmpty(newName)) { newName = sourceDirectory.Name; } string targetVirtualDirectoryPath = VirtualPathUtility.Combine(targetDirectory.VirtualPath, newName); // TODO: Move this logic into UnifiedDirectoey it shouldn't be possible to orphan directories. if (!ValidatePathStructureForMove(sourceDirectory.VirtualPath, targetVirtualDirectoryPath)) { throw new ArgumentException("Moving a folder below itself is not allowed."); } UnifiedDirectory unifiedSourceDirectory = sourceDirectory as UnifiedDirectory; if (unifiedSourceDirectory != null) { if (unifiedSourceDirectory.Parent.VirtualPath != targetDirectory.VirtualPath) { VersioningDirectory versioningDirectory = sourceDirectory as VersioningDirectory; if (versioningDirectory != null) { ThrowIfCheckedOut(versioningDirectory); } } unifiedSourceDirectory.MoveTo(targetVirtualDirectoryPath); } // If source directory isn't a UnifiedDirectory we can't move it. }
public static string ResolveAppRelativePath(this HtmlHelper html, string filename) { Guard.IsNotNullNorWhitespace(filename, nameof(filename)); var server = html.ViewContext.HttpContext.Server; if (VirtualPathUtility.IsAppRelative(filename)) { return(filename); } var view = html.ViewContext.View; if (view is BuildManagerCompiledView) { var viewPath = ((BuildManagerCompiledView)view).ViewPath; var basePath = VirtualPathUtility.GetDirectory(viewPath); return(VirtualPathUtility.Combine(basePath, filename)); } else if (html.ViewDataContainer is WebPageBase) { var viewPath = (html.ViewDataContainer as WebPageBase).VirtualPath; var basePath = VirtualPathUtility.GetDirectory(viewPath); return(VirtualPathUtility.Combine(basePath, filename)); } // XXX: Should we throw here instead?? (pruiz) return(filename); }
public string ToFullUrl(string url) { if (Uri.IsWellFormedUriString(url, UriKind.Absolute)) { return(url); } if (url.IsEmpty()) { url = "~/"; } var urlParts = url.Split(new[] { '?' }, 2); var baseUrl = urlParts[0]; if (baseUrl.IsEmpty()) { baseUrl = "~/"; } if (!VirtualPathUtility.IsAbsolute(baseUrl)) { baseUrl = VirtualPathUtility.Combine("~", baseUrl); } var absoluteUrl = VirtualPathUtility.ToAbsolute(baseUrl); if (urlParts.Length > 1) { absoluteUrl += ("?" + urlParts[1]); } return(absoluteUrl); }
/// <summary> /// Copies a file to the target folder, optionally with a new file name. /// </summary> /// <param name="sourceFile">The source file.</param> /// <param name="targetDirectory">The target directory.</param> /// <param name="newName">The new name. Supply <c>null</c> to use the name of the source file.</param> public static void CopyFile(VirtualFile sourceFile, UnifiedDirectory targetDirectory, string newName) { if (String.IsNullOrEmpty(newName)) { newName = sourceFile.Name; } string targetVirtualFilePath = VirtualPathUtility.Combine(targetDirectory.VirtualPath, newName); targetVirtualFilePath = FindAvailableVirtualPath(targetVirtualFilePath); UnifiedFile unifiedSourceFile = sourceFile as UnifiedFile; if (unifiedSourceFile != null) { // If the source file is a UnifiedFile use its copy implementation unifiedSourceFile.CopyTo(targetVirtualFilePath); } else { // If the source is unknown. i.e. implementing VirtualFile but not UnifiedFile. // Use the support methods of UnifiedFile to copy the source VirtualFile. UnifiedFile.CopyTo(sourceFile, targetVirtualFilePath); } //TODO: Implement copying of VersioningFile to a non-versioning provider. // The versioning providers overrides the [Copy/Move]To methods of UnifiedFile, // but throws an exception if trying to move or copy a file FROM a versioning // provider to another provider }
/// <summary> /// 在指定虚拟路径上溯搜索指定文件名的文件 /// </summary> /// <param name="provider">自定义的虚拟路径提供程序</param> /// <param name="virtualPath">要搜索的虚拟路径</param> /// <param name="fileNames">要搜索的文件名列表</param> /// <returns>返回找到的文件路径,若无法找到匹配的文件,则返回null</returns> public static string FallbackSearch(VirtualPathProvider provider, string virtualPath, params string[] fileNames) { if (!VirtualPathUtility.IsAppRelative(virtualPath)) { throw VirtualPathFormatError("virtualPath"); } while (true) { virtualPath = GetParentDirectory(virtualPath); if (virtualPath == null) { break; } foreach (var name in fileNames) { var filePath = VirtualPathUtility.Combine(virtualPath, name); if (provider.FileExists(filePath)) { return(filePath); } } } return(null); }
public static string MakeAbsolute(string basePath, string relativePath) { string query; basePath = TrimQueryStrings(basePath, out query); return(VirtualPathUtility.Combine(basePath, relativePath)); }
/// <summary> /// Gets a configuration section from the current application's default configuration /// or from the calling assembly's configuration located in the same directory. /// </summary> /// <param name="fromCallingAssembly">Determines whether the configuration instance should be /// retrieved from the web.config located in the calling assembly's directory or from the main /// application's web.config.</param> /// <returns> /// Returns the configuration element within the specified location or null. /// </returns> public static BaseConfiguration GetInstance(bool fromCallingAssembly) { string pluginSectionName = string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings.Get("PluginSectionName")) ? DefaultPluginSection : ConfigurationManager.AppSettings.Get("PluginSectionName"); var config = ConfigurationManager.GetSection(pluginSectionName) as BaseConfiguration; if (!fromCallingAssembly) { return(config); } if (config != null) { var assembly = Assembly.GetCallingAssembly(); var virtualroot = HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? HttpRuntime.AppDomainAppVirtualPath: HttpRuntime.AppDomainAppVirtualPath + "/"; var assemblyloc = VirtualPathUtility.ToAppRelative(VirtualPathUtility.GetDirectory(assembly .Location.Replace(HttpRuntime.AppDomainAppPath, virtualroot))); string configpath = VirtualPathUtility.Combine(assemblyloc, "web.config"); var moduleconfig = WebConfigurationManager.OpenWebConfiguration(configpath); if (moduleconfig != null) { return(moduleconfig.GetSection(pluginSectionName) as BaseConfiguration); } } return(config); }
public void ConstructorThrowsWhenTemplateNotFound() { var templateFile = @"FileNotFound.xml"; Assert.ThrowsArgument( () => { new Chart( GetContext(), GetVirtualPathProvider(), 100, 100, themePath: templateFile ); }, "themePath", String.Format( "The theme file \"{0}\" could not be found.", VirtualPathUtility.Combine( GetContext().Request.AppRelativeCurrentExecutionFilePath, templateFile ) ) ); }
static string GenerateClientUrl(HttpContextBase httpContext, string?basePath, string path, params object?[]?pathParts) { if (String.IsNullOrEmpty(path)) { return(path); } if (basePath != null) { path = VirtualPathUtility.Combine(basePath, path); } string query; string processedPath = UrlBuilder.BuildUrl(path, out query, pathParts); // many of the methods we call internally can't handle query strings properly, so tack it on after processing // the virtual app path and url rewrites if (String.IsNullOrEmpty(query)) { return(GenerateClientUrlInternal(httpContext, processedPath)); } else { return(GenerateClientUrlInternal(httpContext, processedPath) + query); } }
/// <summary> /// Only so we can add users to the adminstrators role. /// </summary> private void ReadMembershipDataStore() { var fullyQualifiedPath = VirtualPathUtility.Combine( VirtualPathUtility.AppendTrailingSlash(HttpRuntime.AppDomainAppVirtualPath), BlogSettings.Instance.StorageLocation + "users.xml"); lock (this) { if (this.userNames != null) { return; } this.userNames = new List <string>(); var doc = new XmlDocument(); if (fullyQualifiedPath != null) { var thepath = HostingEnvironment.MapPath(fullyQualifiedPath); if (thepath != null) { doc.Load(thepath); } } var nodes = doc.GetElementsByTagName("User"); foreach (var userName in nodes.Cast <XmlNode>().Select(node => node["UserName"]).Where(userName => userName != null)) { this.userNames.Add(userName.InnerText); } } }
private void btnCopyDlgSaveChanges_Click(object sender, EventArgs e) { if (Page.IsValid) { var user = UserController.Instance.GetCurrentUserInfo(); string baseVirtualPath; if (user.IsSuperUser && chbCopyToHost.Checked) { baseVirtualPath = PathHelper.ViewsVirtualPath; } else { baseVirtualPath = DnnPathHelper.GetViewsVirtualPath(); } var virtualPath = VirtualPathUtility.Combine(baseVirtualPath, txtViewSetName.Text); var sourceDirectory = new DirectoryInfo(Server.MapPath(ddlViewSets.SelectedValue)); var targetDirectory = new DirectoryInfo(Server.MapPath(virtualPath)); if (targetDirectory.Exists) { msg.ShowError(Localization.GetString("ExistingViewset")); } else { CopyFilesRecursively(sourceDirectory, targetDirectory); msg.ShowOk(string.Format(Localization.GetString("ViewsetCreated"), targetDirectory.FullName)); } } }
/// <summary> /// Maps an embedded resource ID into a web application relative path (~/path). /// </summary> /// <param name="baseNamespace"> /// The base namespace of the resource to map. /// </param> /// <param name="resourcePath"> /// The fully qualified embedded resource path to map. /// </param> /// <returns>The mapped path of the resource into the web application.</returns> /// <remarks> /// <para> /// The <paramref name="baseNamespace" /> is stripped from the front of the /// <paramref name="resourcePath" /> and all but the last period in the remaining /// <paramref name="resourcePath" /> is replaced with the directory separator character /// ('/'). Finally, that path is mapped into a web application relative path. /// </para> /// <para> /// The filename being mapped must have an extension associated with it, and that /// extension may not have a period in it. Only one period will be kept in the /// mapped filename - others will be assumed to be directory separators. If a filename /// has multiple extensions (i.e., <c>My.Custom.config</c>), it will not map properly - /// it will end up being <c>~/My/Custom.config</c>. /// </para> /// <para> /// If <paramref name="baseNamespace" /> does not occur at the start of the /// <paramref name="resourcePath" />, an <see cref="System.InvalidOperationException"/> /// is thrown. /// </para> /// </remarks> /// <example> /// <para> /// Given a <paramref name="baseNamespace" /> of <c>MyNamespace</c>, /// this method will process <paramref name="resourcePath" /> as follows: /// </para> /// <list type="table"> /// <listheader> /// <term><paramref name="resourcePath" /> value</term> /// <description>Mapping in Web App</description> /// </listheader> /// <item> /// <term><c>MyNamespace.Config.MyFile.config</c></term> /// <description><c>~/Config/MyFile.config</c></description> /// </item> /// <item> /// <term><c>MyNamespace.MyPage.aspx</c></term> /// <description><c>~/MyPage.aspx</c></description> /// </item> /// </list> /// </example> /// <exception cref="System.ArgumentNullException"> /// Thrown if <paramref name="baseNamespace" /> or <paramref name="resourcePath" /> is <see langword="null" />. /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown if <paramref name="baseNamespace" /> or <paramref name="resourcePath" />: /// <list type="bullet"> /// <item> /// <description> /// Is <see cref="System.String.Empty"/>. /// </description> /// </item> /// <item> /// <description> /// Start or end with period. /// </description> /// </item> /// <item> /// <description> /// Contain two or more periods together (like <c>MyNamespace..MySubnamespace</c>). /// </description> /// </item> /// </list> /// </exception> /// <seealso cref="GSF.Web.Hosting.EmbeddedResourcePathProvider" /> protected static string MapResourceToWebApplication(string baseNamespace, string resourcePath) { // Validate parameters ValidateResourcePath("baseNamespace", baseNamespace); ValidateResourcePath("resourcePath", resourcePath); // Ensure that the base namespace (with the period delimiter) appear in the resource path if (resourcePath.IndexOf(baseNamespace + ".") != 0) { throw new InvalidOperationException("Base resource namespace must appear at the start of the embedded resource path."); } // Remove the base namespace from the resource path string newResourcePath = resourcePath.Remove(0, baseNamespace.Length + 1); // Find the last period - that's the file extension int extSeparator = newResourcePath.LastIndexOf(".", StringComparison.Ordinal); // Replace all but the last period with a directory separator string resourceFilePath = newResourcePath.Substring(0, extSeparator).Replace(".", "/") + newResourcePath.Substring(extSeparator, newResourcePath.Length - extSeparator); // Map the path into the web app and return string retVal = VirtualPathUtility.Combine("~/", resourceFilePath); return(retVal); }
public bool TryFindExistingMedia(int parentNodeId, string fileName, out Media existingMedia) { var children = parentNodeId == -1 ? Media.GetRootMedias() : new Media(parentNodeId).Children; foreach (var childMedia in children) { if (childMedia.ContentType.Alias == MediaTypeAlias) { var prop = childMedia.getProperty("umbracoFile"); if (prop != null) { var destFileName = ConstructDestFileName(prop.Id, fileName); var destPath = ConstructDestPath(prop.Id); var destFilePath = VirtualPathUtility.Combine(destPath, destFileName); if (prop.Value.ToString() == destFilePath) { existingMedia = childMedia; return(true); } } } } existingMedia = null; return(false); }
public static string Minify(System.Web.Mvc.UrlHelper urlHelper, string cssPath, string requestPath, string cssContent) { // this construct is to enable us to refer to the relativePath above ... MatchEvaluator urlDelegate = new MatchEvaluator(delegate(Match m) { // Change relative (to the original CSS) URL references to make them relative to the requested URL (controller / action) string url = m.Value; Uri uri = new Uri(url, UriKind.RelativeOrAbsolute); if (uri.IsAbsoluteUri || VirtualPathUtility.IsAbsolute(url)) { // if the URL is absolute ("http://server/path/file.ext") or app absolute ("/path/file.ext") then leave it as it is } else { // get app relative url url = VirtualPathUtility.Combine(cssPath, url); url = VirtualPathUtility.MakeRelative(requestPath, url); url = urlHelper.Content(url); } return(url); }); return(Minify(urlHelper, urlDelegate, cssContent, 0)); }
public void Process(BundleContext context, BundleResponse response) { response.Content = string.Empty; foreach (BundleFile file in response.Files) { using (var reader = new StreamReader(file.VirtualFile.Open())) { var contents = reader.ReadToEnd(); var matches = pattern.Matches(contents); if (matches.Count > 0) { var directoryPath = VirtualPathUtility.GetDirectory(file.VirtualFile.VirtualPath); foreach (Match match in matches) { var fileRelativePath = match.Groups[2].Value; var fileVirtualPath = VirtualPathUtility.Combine(directoryPath, fileRelativePath); var quote = match.Groups[1].Value; var replace = String.Format("url({0}{1}{0})", quote, VirtualPathUtility.ToAbsolute(fileVirtualPath)); contents = contents.Replace(match.Groups[0].Value, replace); } } response.Content = String.Format("{0}\r\n{1}", response.Content, contents); } } }
public static IHtmlString RenderFormat(string tagFormat, string bundleVirtualPath) { if (BundleTable.EnableOptimizations) { var url = BundleResolver.Current.GetBundleUrl(bundleVirtualPath); return(new HtmlString(string.Format(tagFormat, url))); } var bundleContext = new BundleContext(new HttpContextWrapper(HttpContext.Current), BundleTable.Bundles, bundleVirtualPath); var bundle = BundleTable.Bundles.GetBundleFor(bundleVirtualPath); if (bundle == null) { throw new ArgumentException("Bundle for virutal path could not be found.", nameof(bundleVirtualPath)); } var builder = new StringBuilder(); builder.AppendLine("<style>"); foreach (var file in bundle.EnumerateFiles(bundleContext)) { var className = GetClassName(file.VirtualFile.Name); var context = HttpContext.Current; var virtualPath = VirtualPathUtility.Combine(context.Request.AppRelativeCurrentExecutionFilePath, file.VirtualFile.VirtualPath); var absolutePath = VirtualPathUtility.ToAbsolute(virtualPath); builder.AppendLine($" .{className} {{ background-image: url({HttpUtility.UrlPathEncode(absolutePath)}); }}"); } builder.AppendLine("</style>"); return(new HtmlString(builder.ToString())); }
public static string MakeAbsolute(string basePath, string relativePath) { string text; basePath = StripQuery(basePath, out text); return(VirtualPathUtility.Combine(basePath, relativePath)); }
/// <summary> /// Moves a virtual file to a new directory, optioanlly renaming it in the process. /// </summary> /// <param name="sourceFile">The source file to be moved.</param> /// <param name="targetDirectory">The destination directory.</param> /// <param name="newName">An optional new name. Supply <c>null</c> to use the original name of the source file.</param> public static void MoveFile(VirtualFile sourceFile, UnifiedDirectory targetDirectory, string newName) { if (String.IsNullOrEmpty(newName)) { newName = sourceFile.Name; } string targetVirtualFilePath = VirtualPathUtility.Combine(targetDirectory.VirtualPath, newName); UnifiedFile unifiedSourceFile = sourceFile as UnifiedFile; if (unifiedSourceFile != null) { IVersioningFile versioningFile = sourceFile as IVersioningFile; if (versioningFile != null) { ThrowIfCheckedOut(versioningFile); } if (!IsPathAvailable(targetVirtualFilePath)) { throw new ArgumentException("Moving a file with the same name as a file or a folder in the target directory is not allowed"); } unifiedSourceFile.MoveTo(targetVirtualFilePath); } // Can't move a file unless its a UnifiedFile. VirtualFile does not specify any remove methods. }
public static bool CreateHistory(SharedFile file, IFileSystem fileSystem, string virtualFilePath, string virtualHistoryPath) { bool historyCreated = false; //File.Move(Path.Combine(sourceFilePath, Path.GetFileName(this.serverFileName)), Path.Combine(historyFolderPath, Path.GetFileName(this.serverFileName))); fileSystem.MoveFile( VirtualPathUtility.Combine(virtualFilePath, file.ServerFileName), VirtualPathUtility.Combine(virtualHistoryPath, file.ServerFileName), true); historyCreated = SharedFile.AddHistory( file.ItemGuid, file.ModuleGuid, file.UserGuid, file.ItemId, file.ModuleId, file.FriendlyName, file.OriginalFileName, file.ServerFileName, file.SizeInKB, file.UploadDate, file.UploadUserId, file.ViewRoles ); return(historyCreated); }
public MailMessage CreateMailMessage(string recipients, IDictionary replacements, Control owner) { if (owner == null) { throw new ArgumentNullException("owner"); } string bodyText = null; if (BodyFileName.Length > 0) { string filePath = null; if (Path.IsPathRooted(BodyFileName)) { filePath = BodyFileName; } else { filePath = HttpContext.Current.Request.MapPath(VirtualPathUtility.Combine(owner.TemplateSourceDirectory, BodyFileName)); } using (StreamReader sr = new StreamReader(filePath)) { bodyText = sr.ReadToEnd(); } } else { bodyText = ""; } return(CreateMailMessage(recipients, replacements, bodyText, owner)); }
private void DeleteItem(GridViewRow e) { string keys = dgFile.DataKeys[e.RowIndex].Value.ToString(); char[] separator = { '~' }; string[] args = keys.Split(separator); string type = args[1]; if (type == "folder") { int folderID = int.Parse(args[0]); SharedFileFolder folder = new SharedFileFolder(this.ModuleId, folderID); //folder.DeleteAllFiles(this.filePath); SharedFilesHelper.DeleteAllFiles(folder, fileSystem, fileVirtualBasePath, config); SharedFileFolder.DeleteSharedFileFolder(folderID); //TODO: file content changed event so re-index } if (type == "file") { int fileID = int.Parse(args[0]); SharedFile sharedFile = new SharedFile(this.ModuleId, fileID); if (!config.EnableVersioning) { fileSystem.DeleteFile(VirtualPathUtility.Combine(fileVirtualBasePath, sharedFile.ServerFileName)); } sharedFile.Delete(); sharedFile.ContentChanged += new ContentChangedEventHandler(SharedFile_ContentChanged); } }
// MembershipProvider Methods public override void Initialize(string name, NameValueCollection config) { // Verify that config isn't null if (config == null) { throw new ArgumentNullException("config"); } // Assign the provider a default name if it doesn't have one if (String.IsNullOrEmpty(name)) { name = "ReadOnlyXmlMembershipProvider"; } // Add a default "description" attribute to config if the // attribute doesn't exist or is empty if (string.IsNullOrEmpty(config["description"])) { config.Remove("description"); config.Add("description", "Read-only XML membership provider"); } // Call the base class's Initialize method base.Initialize(name, config); // Initialize _XmlFileName and make sure the path // is app-relative string path = config["xmlFileName"]; if (String.IsNullOrEmpty(path)) { path = "~/App_Data/Users.xml"; } if (!VirtualPathUtility.IsAppRelative(path)) { throw new ArgumentException ("xmlFileName must be app-relative"); } string fullyQualifiedPath = VirtualPathUtility.Combine (VirtualPathUtility.AppendTrailingSlash (HttpRuntime.AppDomainAppVirtualPath), path); _XmlFileName = HostingEnvironment.MapPath(fullyQualifiedPath); config.Remove("xmlFileName"); // Make sure we have permission to read the XML data source and // throw an exception if we don't FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Read, _XmlFileName); permission.Demand(); // Throw an exception if unrecognized attributes remain if (config.Count > 0) { string attr = config.GetKey(0); if (!String.IsNullOrEmpty(attr)) { throw new ProviderException ("Unrecognized attribute: " + attr); } } }
private string ResolveUrlPath(string virtualPath, Match m) { if (m.Success && m.Groups[1].Success) { var path = m.Groups[1].Value.Trim().Trim('\'', '"'); if (path.StartsWith("data:", StringComparison.InvariantCultureIgnoreCase)) { return(m.Value); } if (Uri.IsWellFormedUriString(path, UriKind.Relative)) { path = VirtualPathUtility.Combine(VirtualPathUtility.GetDirectory(virtualPath), path); } else if (path.StartsWith(Uri.UriSchemeHttp)) { path = new Uri(path).PathAndQuery; } if (HostingEnvironment.ApplicationVirtualPath != "/" && path.StartsWith(HostingEnvironment.ApplicationVirtualPath)) { path = path.Substring(HostingEnvironment.ApplicationVirtualPath.Length); } if (path.StartsWith("/")) { path = "~" + path; } path = VirtualPathUtility.MakeRelative(bundlepath, path).ToLowerInvariant(); return(m.Value.Replace(m.Groups[1].Value, "\"" + path + "\"")); } return(m.Value); }
public override bool UpdateItem(ContentItem item, Control editor) { SelectingUploadCompositeControl composite = (SelectingUploadCompositeControl)editor; HttpPostedFile postedFile = composite.UploadControl.PostedFile; if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName)) { IFileSystem fs = Engine.Resolve <IFileSystem>(); string directoryPath = Engine.Resolve <IDefaultDirectory>().GetDefaultDirectory(item); if (!fs.DirectoryExists(directoryPath)) { fs.CreateDirectory(directoryPath); } string fileName = Path.GetFileName(postedFile.FileName); fileName = Regex.Replace(fileName, InvalidCharactersExpression, "-"); string filePath = VirtualPathUtility.Combine(directoryPath, fileName); fs.WriteFile(filePath, postedFile.InputStream); item[Name] = Url.ToAbsolute(filePath); return(true); } if (composite.SelectorControl.Url != item[Name] as string) { item[Name] = composite.SelectorControl.Url; return(true); } return(false); }
/// <summary> /// The get ascii full path to template. /// </summary> /// <param name="templateFileName"> /// The template file name. /// </param> /// <returns> /// The <see cref="string"/>. /// </returns> private string GetAsciiFullPathToTemplate(string templateFileName) { if (HttpContext.Current != null) { return (HttpContext.Current.Server.MapPath( VirtualPathUtility.Combine(this.asciiTemplatesDirectory, templateFileName))); } if (!Directory.Exists(this.asciiTemplatesDirectory)) { var callingAssembly = Assembly.GetCallingAssembly(); return (Path.Combine( callingAssembly.Location.TrimEndStrings( callingAssembly.GetName().Name + ".exe", callingAssembly.GetName().Name + ".dll") + this.asciiTemplatesDirectory, templateFileName)); } else { return(Path.Combine(this.asciiTemplatesDirectory, templateFileName)); } }
private static string GetUrl(VirtualFile file) { string dir = VirtualPathUtility.GetDirectory(file.VirtualPath); string filePath = Path.GetFileNameWithoutExtension(file.VirtualPath); return(VirtualPathUtility.Combine(dir, filePath).ToLowerInvariant()); }
private static HelpTopic CreateTopic(string virtualPath) { if (virtualPath == null) { throw new ArgumentNullException("virtualPath"); } virtualPath = VirtualPathUtility.Combine(helpEntriesVirtualPath, virtualPath); if (VirtualPathProvider.DirectoryExists(virtualPath)) { return(new HelpCategory(virtualPath)); } else if (VirtualPathProvider.FileExists(virtualPath)) { return(new HelpEntry(virtualPath)); } else { return(null); } }