本文整理汇总了C#中IFileProvider.GetFileInfo方法的典型用法代码示例。如果您正苦于以下问题:C# IFileProvider.GetFileInfo方法的具体用法?C# IFileProvider.GetFileInfo怎么用?C# IFileProvider.GetFileInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IFileProvider
的用法示例。
在下文中一共展示了IFileProvider.GetFileInfo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BaseDocumentHandler
public BaseDocumentHandler(IFileProvider fileProvider, string subpath)
{
FileInfo = AcceptedExtensions
.Select(x => fileProvider.GetFileInfo(subpath + x))
.Where(x => x.Exists)
.FirstOrDefault();
}
示例2: ReadFileContentsSafely
private static string ReadFileContentsSafely(IFileProvider fileProvider, string filePath)
{
var fileInfo = fileProvider.GetFileInfo(filePath);
if (fileInfo.Exists)
{
try
{
using (var reader = new StreamReader(fileInfo.CreateReadStream()))
{
return reader.ReadToEnd();
}
}
catch
{
// Ignore any failures
}
}
return null;
}
示例3: ResolveFilePath
internal ResolveFilePathResult ResolveFilePath(IFileProvider fileProvider)
{
// Let the file system try to get the file and if it can't,
// fallback to trying the path directly unless the path starts with '/'.
// In that case we consider it relative and won't try to resolve it as
// a full path
var path = NormalizePath(FileName);
// Note that we cannot use 'File.Exists' check as the file could be a non-physical
// file. For example, an embedded resource.
if (IsPathRooted(path))
{
// The path is absolute
// C:\...\file.ext
// C:/.../file.ext
return new ResolveFilePathResult()
{
PhysicalFilePath = path
};
}
var fileInfo = fileProvider.GetFileInfo(path);
if (fileInfo.Exists)
{
// The path is relative and IFileProvider found the file, so return the full
// path.
return new ResolveFilePathResult()
{
// Note that physical path could be null in case of non-disk file (ex: embedded resource)
PhysicalFilePath = fileInfo.PhysicalPath,
FileInfo = fileInfo
};
}
// We are absolutely sure the path is relative, and couldn't find the file
// on the file system.
var message = Resources.FormatFileResult_InvalidPath(path);
throw new FileNotFoundException(message, path);
}
示例4: SuiteWidgets
public static IEnumerable<NavigationWidget> SuiteWidgets(IFileProvider fileProvider)
{
var file = fileProvider.GetFileInfo("/shared/nav-beta.json");
var navigationJson = IOFile.ReadAllText(file.PhysicalPath);
return JsonConvert.DeserializeObject<IEnumerable<NavigationWidget>>(navigationJson);
}