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


C# VirtualPath.OpenFile方法代码示例

本文整理汇总了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;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:32,代码来源:Control.cs

示例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();
        }
    }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:11,代码来源:Util.cs

示例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);
        }
    }
开发者ID:uQr,项目名称:referencesource,代码行数:38,代码来源:TemplateParser.cs

示例4: OpenStream

 internal /*protected*/ Stream OpenStream(VirtualPath virtualPath) {
     return virtualPath.OpenFile();
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:3,代码来源:BuildProvider.cs


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