当前位置: 首页>>代码示例>>C#>>正文


C# FileInfo.GetRelativePath方法代码示例

本文整理汇总了C#中System.IO.FileInfo.GetRelativePath方法的典型用法代码示例。如果您正苦于以下问题:C# FileInfo.GetRelativePath方法的具体用法?C# FileInfo.GetRelativePath怎么用?C# FileInfo.GetRelativePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.FileInfo的用法示例。


在下文中一共展示了FileInfo.GetRelativePath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateCommentBody

        private string CreateCommentBody(IRenderingContext targetContext,
                                     bool skipLineNumber,
                                     string extraText,
                                     bool useEndTagPosition,
                                     IRenderingContext replacementContext)
        {
            IZptElement
            targetElement = targetContext.Element,
            sourceElement = replacementContext?.Element ?? targetContext.Element;
              string
            fullFilename = targetContext.Element.SourceFile.FullName,
            filename,
            filePosition = useEndTagPosition? sourceElement.GetEndTagFileLocation() : sourceElement.GetFileLocation(),
            previousElement;

              if(!String.IsNullOrEmpty(targetContext.SourceAnnotationRootPath)
             && Directory.Exists(targetContext.SourceAnnotationRootPath)
             && File.Exists(fullFilename))
              {
            var root = new DirectoryInfo(targetContext.SourceAnnotationRootPath);
            var file = new FileInfo(fullFilename);
            filename = file.IsChildOf(root)? file.GetRelativePath(root).Substring(1) : fullFilename;
              }
              else
              {
            filename = fullFilename;
              }

              filename = filename.Replace(Path.DirectorySeparatorChar.ToString(), "/");

              if((!targetElement.IsRoot && targetElement.HasParent) || targetElement.CanWriteCommentWithoutParent)
              {
            previousElement = String.Empty;
              }
              else
              {
            previousElement = PREVIOUS_ELEMENT;
              }

              var body = (skipLineNumber || String.IsNullOrEmpty(filePosition))? filename : String.Format(POSITION_FORMAT, filename, filePosition);
              var extra = _renderExtraText? extraText?? String.Empty : String.Empty;
              return String.Concat(previousElement, extra, body);
        }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:43,代码来源:SourceAnnotator.cs

示例2: TestGetRelative

 public void TestGetRelative()
 {
   FileInfo file = new FileInfo(@"C:\SomeDirectory\SomeFile.txt");
   
   Assert.AreEqual(@"SomeDirectory\SomeFile.txt",
                   file.GetRelativePath(new DirectoryInfo(@"C:\")),
                   "Correct relative path");
 }
开发者ID:csf-dev,项目名称:CSF.Core,代码行数:8,代码来源:TestFileSystemInfoExtensions.cs

示例3: GetOutputFile

        private FileInfo GetOutputFile(DirectoryInfo outputRoot, string extensionOverride)
        {
            if(_inputFile == null)
              {
            throw new BatchRenderingException(Resources.ExceptionMessages.InputMustBeFileIfOutputIsDirectory);
              }

              var extension = _inputFile.Extension;
              var filenameWithoutExtension = _inputFile.Name.Substring(0, _inputFile.Name.Length - extension.Length);
              string newFilename;

              if(extensionOverride != null)
              {
            string newExtension = extensionOverride;
            if(!newExtension.StartsWith("."))
            {
              newExtension = String.Concat(".", newExtension);
            }

            newFilename = String.Concat(filenameWithoutExtension, newExtension);
              }
              else if(_document.Mode == RenderingMode.Xml)
              {
            newFilename = String.Concat(filenameWithoutExtension, ".xml");
              }
              else
              {
            newFilename = String.Concat(filenameWithoutExtension, ".html");
              }

              var tempOutputPath = new FileInfo(System.IO.Path.Combine(_inputFile.GetParentDirectory().FullName, newFilename));

              var relativePath = tempOutputPath.GetRelativePath(_inputRootDirectory);
              if(relativePath.StartsWith(System.IO.Path.DirectorySeparatorChar.ToString()))
              {
            relativePath = relativePath.Substring(1);
              }
              var outputPath = outputRoot.FullName;
              return new FileInfo(System.IO.Path.Combine(outputPath, relativePath));
        }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:40,代码来源:RenderingJob.cs

示例4: TestGetRelativeNotRooted

 public void TestGetRelativeNotRooted()
 {
   FileInfo file = new FileInfo(@"C:\SomeDirectory\SomeFile.txt");
   file.GetRelativePath(new DirectoryInfo(@"D:\"));
   Assert.Fail("Test should not reach this point");
 }
开发者ID:csf-dev,项目名称:CSF.Core,代码行数:6,代码来源:TestFileSystemInfoExtensions.cs


注:本文中的System.IO.FileInfo.GetRelativePath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。