Good time of day for all! I have some troubles, and i hope you guys can help me. I search google, but did not find valid answer for my question. I want to open alternate file streams. If i write something like File.Open("filename:stramname") I receive expetion. It says, that file path in this format is not supported in .NET. Good, i found very simple solution, using CreateFile API and contructor in IO.FileStream class, that receive windows file handle. But. I have to use this code in ASP.NET pages, located in the remote server. And, it seems to me, hosting's security policies forbids applications to use Windows API. Anyway, i recieve <access denided> error, when use any Windows API on the ASP.NET pages, located on the hosting. I do not receive this errors on same code, if it executes on my local machine. So, i want to ask you: How can i open Stream object for the alternate file stream, without using Windows API?
Oh, you really do not understand me. Ok, i ask question in another words. I have stream C:\XXX:ddd Can you write me there really working code, that opens this strram and reads all of data into string variable?
Code: // create reader & open file Textreader tr = new StreamReader(@"C:\123.log"); // read a line of text Console.WriteLine(tr.ReadLine()); // close the stream tr.Close();
This code reads main stream of file C:\123.log I asked you, how to read file stream C:\XXX:ddd Can i give me this code, please?
What you are trying to do requires a seperate class library. Please see this article: http://www.codeproject.com/cs/files/ads.asp
Uhhh, ok? If you still don't have an answer perhaps try asking a better question. Go to google and do a search for "alternate file streams .NET"
Do i ask bad question? I ask how to work with AFS without importing WinAPI, is it hard to understantd?
I admit I did not notice at first glance the part of your inquiry where you stated "without API" , however if you would have just said what you just said which is: "how do I work with AFS without using API?" then that would have been the appropriate question. Code: using System; using System.Runtime.InteropServices; class TestNTFSStream { [DllImport("kernel32.dll")] public static extern IntPtr CreateFile( string lpFileName, int dwDesiredAccess, int dwShareMode, IntPtr lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, IntPtr hTemplateFile ); // some constants look around for ideas of more to use private const int FILE_SHARE_READ = 1; private const int OPEN_EXISTING = 3; private const int INVALID_HANDLE_VALUE = -1; static void Main(string[] args) { //Try to open the file for read only IntPtr hflp = CreateFile( @"c:\filename:AFP_Resource", 0, FILE_SHARE_READ, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero ); if( (int)hflp == INVALID_HANDLE_VALUE ) Console.WriteLine("No such file/stream"); else Console.WriteLine("File found"); } }
forgot to add this little bit of information that may also help. Check the MSDN doc's on deatail about PInvoke.