本文整理汇总了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);
}
示例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");
}
示例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));
}
示例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");
}