本文整理汇总了C#中VirtualPath.OpenFile方法的典型用法代码示例。如果您正苦于以下问题:C# VirtualPath.OpenFile方法的具体用法?C# VirtualPath.OpenFile怎么用?C# VirtualPath.OpenFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VirtualPath
的用法示例。
在下文中一共展示了VirtualPath.OpenFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenFileAndGetDependency
///
/// Open a stream from either a virtual or physical path, and if possible get a CacheDependency
/// for the resulting Stream.
///
internal Stream OpenFileAndGetDependency(VirtualPath virtualPath, string physicalPath, out CacheDependency dependency) {
// Only one of the paths should be non-null
Debug.Assert((virtualPath == null) != (physicalPath == null));
// If we got a virtual path, and we're using the default VPP, call MapPath
if (physicalPath == null && HostingEnvironment.UsingMapPathBasedVirtualPathProvider) {
physicalPath = virtualPath.MapPathInternal(TemplateControlVirtualDirectory,
true /*allowCrossAppMapping*/);
}
Stream stream;
if (physicalPath != null) {
// Security check
HttpRuntime.CheckFilePermission(physicalPath);
// Work directly with the physical file, bypassing the VPP
stream = new FileStream(physicalPath, FileMode.Open, FileAccess.Read, FileShare.Read);
dependency = new CacheDependency(0, physicalPath);
}
else {
// It's non file system based, so go though the VirtualPathProvider
stream = virtualPath.OpenFile();
dependency = VirtualPathProvider.GetCacheDependency(virtualPath);
}
return stream;
}
示例2: StringFromVirtualPath
/*
* Return a String which holds the contents of a file
*/
internal /*public*/ static String StringFromVirtualPath(VirtualPath virtualPath) {
using (Stream stream = virtualPath.OpenFile()) {
// Create a reader on the file, and read the whole thing
TextReader reader = Util.ReaderFromStream(stream, virtualPath);
return reader.ReadToEnd();
}
}
示例3: ParseFile
internal void ParseFile(string physicalPath, VirtualPath virtualPath) {
// Determine the file used for the circular references checker. Normally,
// we use the virtualPath, but we use the physical path if it specified,
// as is the case for <!-- #include file="foo.inc" -->
string fileToReferenceCheck = physicalPath != null ? physicalPath : virtualPath.VirtualPathString;
// Check for circular references of include files
if (_circularReferenceChecker.Contains(fileToReferenceCheck)) {
ProcessError(SR.GetString(SR.Circular_include));
return;
}
// Add the current file to the circular references checker.
_circularReferenceChecker.Add(fileToReferenceCheck);
try {
// Open a TextReader either from the physical or virtual path
StreamReader reader;
if (physicalPath != null) {
using (reader = Util.ReaderFromFile(physicalPath, CurrentVirtualPath)) {
ParseReader(reader, virtualPath);
}
}
else {
// Open a TextReader for the virtualPath we're parsing
using (Stream stream = virtualPath.OpenFile()) {
reader = Util.ReaderFromStream(stream, CurrentVirtualPath);
ParseReader(reader, virtualPath);
}
}
}
finally {
// Remove the current file from the circular references checker
_circularReferenceChecker.Remove(fileToReferenceCheck);
}
}
示例4: OpenStream
internal /*protected*/ Stream OpenStream(VirtualPath virtualPath) {
return virtualPath.OpenFile();
}