當前位置: 首頁>>代碼示例>>C#>>正文


C# Uri.MakeRelativeUri方法代碼示例

本文整理匯總了C#中System.Uri.MakeRelativeUri方法的典型用法代碼示例。如果您正苦於以下問題:C# Uri.MakeRelativeUri方法的具體用法?C# Uri.MakeRelativeUri怎麽用?C# Uri.MakeRelativeUri使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Uri的用法示例。


在下文中一共展示了Uri.MakeRelativeUri方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GenerateRelativePath

        public static string GenerateRelativePath(string from, string to)
        {
            if(String.IsNullOrWhiteSpace(from) || String.IsNullOrWhiteSpace(to))
            {
                throw new ArgumentNullException("Requires paths");
            }

            Uri fromUri = new Uri(from);
            Uri toUri = new Uri(to);

            //The URI schemes have to match in order for the path to be made relative
            if(fromUri.Scheme != toUri.Scheme)
            {
                return to;
            }

            Uri relativeUri = fromUri.MakeRelativeUri(toUri);
            string relative = Uri.UnescapeDataString(relativeUri.ToString());

            //If neccessary to do so, normalise the use of slashes to always be the default for this platform
            if(toUri.Scheme.ToUpperInvariant() == "FILE")
            {
                relative = relative.Replace(Path.AltDirectorySeparatorChar,
                    Path.DirectorySeparatorChar);
            }

            return relative;
        }
開發者ID:JoshKeegan,項目名稱:CVWS.NET,代碼行數:28,代碼來源:Paths.cs

示例2: Format

        public XDocument Format(IDirectoryTreeNode featureNode, GeneralTree<IDirectoryTreeNode> features, DirectoryInfo rootFolder)
        {
            var xmlns = HtmlNamespace.Xhtml;
            var featureNodeOutputPath = Path.Combine(this.configuration.OutputFolder.FullName, featureNode.RelativePathFromRoot);
            var featureNodeOutputUri = new Uri(featureNodeOutputPath);

            var container = new XElement(xmlns + "div", new XAttribute("id", "container"));
            container.Add(this.htmlHeaderFormatter.Format());
            container.Add(this.htmlTableOfContentsFormatter.Format(featureNode.OriginalLocationUrl, features, rootFolder));
            container.Add(this.htmlContentFormatter.Format(featureNode, features));
            container.Add(this.htmlFooterFormatter.Format());

            var body = new XElement(xmlns + "body");
            body.Add(container);

            var head = new XElement(xmlns + "head");
            head.Add(new XElement(xmlns + "title", string.Format("{0}", featureNode.Name)));

            head.Add(new XElement(xmlns + "link",
                         new XAttribute("rel", "stylesheet"),
                         new XAttribute("href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.MasterStylesheet)),
                         new XAttribute("type", "text/css")));

            head.Add(new XElement(xmlns + "link",
                         new XAttribute("rel", "stylesheet"),
                         new XAttribute("href", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.PrintStylesheet)),
                         new XAttribute("type", "text/css"),
                         new XAttribute("media", "print")));

            head.Add(new XElement(xmlns + "script",
                         new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.jQueryScript)),
                         new XAttribute("type", "text/javascript"),
                         new XText(string.Empty)));

            head.Add(new XElement(xmlns + "script",
                         new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.jQueryDataTablesScript)),
                         new XAttribute("type", "text/javascript"),
                         new XText(string.Empty)));

            head.Add(new XElement(xmlns + "script",
                         new XAttribute("src", featureNodeOutputUri.MakeRelativeUri(this.htmlResources.AdditionalScripts)),
                         new XAttribute("type", "text/javascript"),
                         new XText(string.Empty)));

            head.Add(new XElement(xmlns + "script",
                         new XAttribute("type", "text/javascript"),
                         documentReady));

            var html = new XElement(xmlns + "html",
                           new XAttribute(XNamespace.Xml + "lang", "en"),
                           head,
                           body);

            var document = new XDocument(
                                new XDeclaration("1.0", "UTF-8", null),
                                new XDocumentType("html", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd", string.Empty),
                                html);

            return document;
        }
開發者ID:drift,項目名稱:pickles,代碼行數:60,代碼來源:HtmlDocumentFormatter.cs

示例3: Visit

		public override void Visit(Document document)
		{
			var directoryAttribute = document.Attributes.FirstOrDefault(a => a.Name == "docdir");
			if (directoryAttribute != null)
			{
				document.Attributes.Remove(directoryAttribute);
			}

			// check if this document has generated includes to other files
			var includeAttribute = document.Attributes.FirstOrDefault(a => a.Name == "includes-from-dirs");

			if (includeAttribute != null)
			{
				var thisFileUri = new Uri(_destination.FullName);
				var directories = includeAttribute.Value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

				foreach (var directory in directories)
				{
					foreach (var file in Directory.EnumerateFiles(Path.Combine(Program.OutputDirPath, directory), "*.asciidoc", SearchOption.AllDirectories))
					{
						var fileInfo = new FileInfo(file);
						var referencedFileUri = new Uri(fileInfo.FullName);
						var relativePath = thisFileUri.MakeRelativeUri(referencedFileUri);
						var include = new Include(relativePath.OriginalString);

						document.Add(include);
					}
				}
			}

			base.Visit(document);
		}
開發者ID:RossLieberman,項目名稱:NEST,代碼行數:32,代碼來源:RawAsciidocVisitor.cs

示例4: MakeRelative

        private string MakeRelative(string filePath, string referencePath)
        {
            var fileUri = new Uri(filePath);
            var referenceUri = new Uri(referencePath);

            return referenceUri.MakeRelativeUri(fileUri).ToString();
        }
開發者ID:pzielinski86,項目名稱:RuntimeTestCoverage,代碼行數:7,代碼來源:RewrittenDocumentsStorage.cs

示例5: ResolveUri

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public virtual Uri ResolveUri(Uri baseUri, string relativeUri)
        {
            if (baseUri == null || (!baseUri.IsAbsoluteUri && baseUri.OriginalString.Length == 0))
            {
                return new Uri(relativeUri, UriKind.RelativeOrAbsolute);
            }
            else
            {
                if (relativeUri == null || relativeUri.Length == 0)
                {
                    return baseUri;
                }
                // relative base Uri
                if (!baseUri.IsAbsoluteUri)
                {
                    // create temporary base for the relative URIs
                    Uri tmpBaseUri = new Uri("tmp:///");

                    // create absolute base URI with the temporary base
                    Uri absBaseUri = new Uri(tmpBaseUri, baseUri.OriginalString);

                    // resolve the relative Uri into a new absolute URI
                    Uri resolvedAbsUri = new Uri(absBaseUri, relativeUri);

                    // make it relative by removing temporary base
                    Uri resolvedRelUri = tmpBaseUri.MakeRelativeUri(resolvedAbsUri);

                    return resolvedRelUri;
                }
                return new Uri(baseUri, relativeUri);
            }
        }
開發者ID:SamuelEnglard,項目名稱:corefx,代碼行數:35,代碼來源:XmlResolver.cs

示例6: MakeRelative

        public static string MakeRelative(string filePath, string referencePath)
        {
            var fileUri = new Uri(filePath);
            var referenceUri = new Uri(referencePath);

            return Uri.UnescapeDataString(referenceUri.MakeRelativeUri(fileUri).ToString());
        }
開發者ID:jonlawley,項目名稱:HmxSynch,代碼行數:7,代碼來源:UtilityMethods.cs

示例7: MakeRelativePath

        internal static DirectoryPath MakeRelativePath(this DirectoryPath directoryPath, ICakeEnvironment environment, DirectoryPath rootDirectoryPath)
        {
            if (directoryPath == null)
            {
                throw new ArgumentNullException(nameof(directoryPath));
            }

            if (environment == null)
            {
                throw new ArgumentNullException(nameof(environment));
            }

            if (rootDirectoryPath == null)
            {
                throw new ArgumentNullException(nameof(rootDirectoryPath));
            }

            var dirUri = new Uri(directoryPath.MakeAbsolute(environment).FullPath);
            var rootUri = new Uri($"{rootDirectoryPath.MakeAbsolute(environment).FullPath}/");

            var relativeUri = rootUri.MakeRelativeUri(dirUri);
            var relativePath = Uri.UnescapeDataString(relativeUri.ToString());

            var relativeDirectoryPath = new DirectoryPath(relativePath);

            return relativeDirectoryPath;
        }
開發者ID:Redth,項目名稱:Cake_Git,代碼行數:27,代碼來源:PathExtensions.cs

示例8: GetPathRelativeTo

		string GetPathRelativeTo(string BasePath, string ToPath)
		{
			Uri path1 = new Uri(BasePath);
			Uri path2 = new Uri(ToPath);
			Uri diff = path1.MakeRelativeUri(path2);
			return diff.ToString();
		}
開發者ID:zhaoyizheng0930,項目名稱:UnrealEngine,代碼行數:7,代碼來源:CodeLiteProject.cs

示例9: MakeRelative

 public static string MakeRelative(string basePath, string absolutePath)
 {
     Uri baseUri = new Uri(basePath);
     Uri absoluteUri = new Uri(absolutePath);
     var result = absoluteUri.MakeRelativeUri(baseUri);
     return result.OriginalString;
 }
開發者ID:DmytroMelnyk,項目名稱:MyCommander,代碼行數:7,代碼來源:PathHelper.cs

示例10: ObterPastaRelativa

 private string ObterPastaRelativa(string projectFileName, string basePath)
 {
     Uri uriProjectPath = new Uri(Path.GetFullPath(projectFileName));
     Uri uriBasePath = new Uri(basePath);
     Uri uriRelativa = uriProjectPath.MakeRelativeUri(uriBasePath);
     return uriRelativa.ToString();
 }
開發者ID:rooseveltdossantos,項目名稱:produtividade,代碼行數:7,代碼來源:AjustadorOutputCSProj.cs

示例11: MakeRelativePath

        public static string MakeRelativePath(string relativeDirectory,string filename)
        {
            try
            {
                if( filename.Length == 0 || IsUNC(filename) || IsRelative(filename) )
                    return filename;

                Uri fileUri = new Uri(filename);
                Uri referenceUri = new Uri(relativeDirectory + "/");

                string relativePath = referenceUri.MakeRelativeUri(fileUri).ToString();
                relativePath = Uri.UnescapeDataString(relativePath);
                relativePath = relativePath.Replace('/','\\');

                if( relativePath.IndexOf(':') < 0 && relativePath[0] != '.' ) // add a .\ (as CSPro does)
                    relativePath = ".\\" + relativePath;

                return relativePath;
            }

            catch( Exception )
            {
            }

            return filename;
        }
開發者ID:jhandley,項目名稱:tools,代碼行數:26,代碼來源:Paths.cs

示例12: FindFiles

        public IEnumerable<string> FindFiles(string baseDir, IEnumerable<string> ignores)
        {
            List<string> filesToParse = new List<string>();

            List<string> files = new List<string>();
            files.AddRange(Directory.GetFiles(baseDir, "*.lua", SearchOption.AllDirectories));
            files.AddRange(Directory.GetFiles(baseDir, "*.ns2doc", SearchOption.AllDirectories));

            foreach (string path in files)
            {

                Uri fileNameUri = new Uri("file://" + path);
                Uri baseDirUri = new Uri("file://" + baseDir);
                string fileName = Uri.UnescapeDataString(baseDirUri.MakeRelativeUri(fileNameUri).ToString());

                bool skip = false;
                foreach (string ignore in ignores)
                {
                    if (ignore.StartsWith("~"))
                    {
                        skip = !fileName.StartsWith(ignore.Substring(1));
                    }
                    else if (fileName.StartsWith(ignore))
                    {
                        skip = true;
                        break;
                    }
                }
                if (!skip)
                {
                    filesToParse.Add(path);
                }
            }
            return filesToParse;
        }
開發者ID:DamienHauta,項目名稱:Ns2Docs,代碼行數:35,代碼來源:Program.cs

示例13: GetRelativePath

        public static string GetRelativePath(string currentDirectory, string filePath)
        {
            var uriFile = new Uri(filePath);
            var uriCurrentDir = new Uri(currentDirectory + (!currentDirectory.EndsWith("\\") ? "\\" : ""));

            return uriCurrentDir.MakeRelativeUri(uriFile).ToString();
        }
開發者ID:kirkpabk,項目名稱:higgs,代碼行數:7,代碼來源:IOHelpers.cs

示例14: FormSaveSettings

        public FormSaveSettings(string saveLocation, FormWorld world)
        {
            InitializeComponent();

            this.saveLocation = saveLocation;
            this.world = world;

            var saveUri = new Uri(saveLocation);

            foreach (var tileset in world.Tilesets)
            {
                string relative = saveUri.MakeRelativeUri(new Uri(tileset.Filename)).ToString();

                Node node = new Node(Path.GetFileName(tileset.Filename))
                {
                    CheckBoxVisible = true,
                    Checked = tileset.ShouldBuild
                };

                Cell cell = new Cell()
                {
                    Text = tileset.BuildLocation != null ? tileset.BuildLocation : 
                           Path.Combine(Path.GetDirectoryName(relative), Path.GetFileNameWithoutExtension(relative)),
                    Editable = true
                };

                node.Cells[0].Editable = false;

                node.Cells.Add(cell);

                tilesetFilesList.Nodes.Add(node);
            }
        }
開發者ID:AustinBrunkhorst,項目名稱:XNA-World-Editor,代碼行數:33,代碼來源:FormSaveSettings.cs

示例15: MakeRelative

        private static string MakeRelative(string baseFile, string file)
        {
            Uri baseUri = new Uri(baseFile, UriKind.RelativeOrAbsolute);
            Uri fileUri = new Uri(file, UriKind.RelativeOrAbsolute);

            return baseUri.MakeRelativeUri(fileUri).ToString();
        }
開發者ID:NelsonReis,項目名稱:BundlerMinifier,代碼行數:7,代碼來源:BundlerBuildTask.cs


注:本文中的System.Uri.MakeRelativeUri方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。