system.io

StreamReader, C#, peek

Hello, I have a StreamReader that once in a while check if it has more to read from a simple text file. It uses peek property. The problem is that when I am using peek the position is changed, althougth not suppose to. FileStream m_fsReader = new FileStream( m_strDataFileName, FileMode.Op...

Code review: Determining whether a folder exists, given the full file path?

With a function being passed a full path to a file, such as C:\someFolder\anotherFolder\someXML.xml, determine whether the folder exists. Is there a smarter/better/more elegant way of doing this? Here is my implementation: Private Function FolderExists(ByVal fullPath As String) As Boolean Dim folders() As String = fullPath.Split("...

CreateText method extension help

Hello. Good day. I found the example below, I need to append some more text from another Sub() function. But i don't know how to. Could you give me some guide? THANKS. using System; using System.IO; public class TextToFile { private const string FILE_NAME = "MyFile.txt"; public static void Main(String[] args) { ...

Cannot execute System.IO.File.Move to a network drive from SharePoint Server 2007 (MOSS).

Hi All, I am using VS2008 C# and MOSS (SharePoint Server 2007). I have created an asp.net web form which appears on a WebPart within a SharePoint site. When submitting the form, a small .csv file is generated. Ideally I want to have this file created on a network drive (on another server), but for some reason I cannot do this. I can c...

"Access to the system path is denied" when using 'System.IO.Directory.Delete'

I'm using System.IO.Directory.Delete and trying to delete system folders such as 'My Music', 'My Videos' etc, but I get errors similar to "Access to the system path 'C:\users\jbloggs\Saved Games' is denied". I can however delete these folders via Explorer without any problems, I have full permissions to these folders. Any suggestions o...

Remove invalid (disallowed, bad) characters from FileName (or Directory, Folder, File) using C# .NET

Hi, I've wrote this little method to achieve the goal in the subj., however, is there more efficient (simpler) way of doing this? I hope this can help somebody who will search for this like I did. var fileName = new System.Text.StringBuilder(); fileName.Append("*Bad/\ :, Filename,? "); // get rid of invalid chars while (fileName.ToStrin...

In MVC 2, How would you determine a file exists at the server using C#?

I know you can do this: if( System.IO.File.Exists( @"C:\INetPub\MVCWebsite\Content\Images\image.jpg") ) { ... } and you can do this to reference files in MVC: Url.Content("~/Content/Images/image.jpg") So is there a way to relatively check that "~/Content/Images/image.jpg" exists (in MVC?)? ...

Using DockPanel Suite's XML saving with My.Settings

In vb.net, how can I use SaveAsXML and LoadFromXML (DockPanel Suite functions) with My.Settings? I know there is a way to save it to a stream, but I don't know enough about System.IO to do this. DockPanel Suite: http://sourceforge.net/projects/dockpanelsuite/ I would very much prefer to store configuration using My.Settings instead of ...

File.Exists() returns false, but not in debug

I'm being completely confused here folks, My code throws an exception because File.Exists() returns false public override sealed TCargo ReadFile(string fileName) { if (!File.Exists(fileName)) { throw new ArgumentException("Provided file name does not exist", "fileName"); } Visual studio breaks at the throw stateme...

Check whether a folder is a local or a network resource in .NET

Is there a quick way to check whether a path I have is on a local disk or somewhere on the network? I can't just check to see if it's a drive letter vs. UNC, because that would incorrectly identify mapped drives as local. I assumed it would be a boolean in the DirectoryInfo object, but it appears that it's not. I've found classic VB cod...

How to determine when file copying is ended?

How to determine when file copying is ended i'm using c# edit: we copying files through network from one pc to another one. my task is to watch directory and do some actions after files are copied to it. ...

How to test if a file is currently being written to.

I have an application that must check a folder and read any files that are copied into it. How do I test if a file in that folder is currently being written to? I only want to read files that have had all their data written to them and are closed. ...

Is there a Base64Stream for .NET? where?

If I want to produce a Base64-encoded output, how would I do that in .NET? I know that since .NET 2.0, there is the ICryptoTransform interface, and the ToBase64Transform() and FromBase64Transform() implementations of that interface. But those classes are embedded into the System.Security namespace, and require the use of a TransformB...

.NET Best Way to move many files to and from various directories??

I've created a program that moves files to and from various directories. An issue I've come across is when you're trying to move a file and some other program is still using it. And you get an error. Leaving it there isn't an option, so I can only think of having to keep trying to move it over and over again. This though slows the en...

Can I read a file from an FTP server, or an HTTP server, as a stream?

Is it possible to read a file over FTP, as a System.IO.Stream ? using (Stream s = Ftp.OpenFile(url....)) { s.Seek(offset, SeekOrigin.Begin); int n = s.Read(...); } and similarly, with HTTP ? using (Stream s = Http.OpenFile(url....)) { s.Seek(offset, SeekOrigin.Begin); int n = s.Read(...); } ...

how to get a list of files / folders as an IEnumerable and not an array

how to get a list of files / folders as an IEnumerable and not an array? the reason I want to do this is a have many folders with 20,000+ files in them, and i need to loop through all of them but do not want to wait for them to be compiled into an array. but just want to go through one at a time. also i'm using .net 3.5 not v4 ...

ASP.NET C# Copy Directory with SubDirectories with System.IO

Hello all, I need to copy a whole directory C:\X to C:\Y\X, and I need the sub-folders to be copied as well. Is there any way to do it with the System.IO.File\Directory namespaces ? Thanks for all helpers! ...

[VB.Net] Does IO.File.Copy replicate files attributes?

Does the IO.File.Copy method preserve file attributes? Especially, if I have a write-protected file, will the copy be write-protected to? ...

Disk IO Performance Limitations based on numbers of folders/files

I have an application where users are allowed to upload images to the server. Our Web Server is a windows 2008 server and we have a site (images.mysite.com) that points to a shared drive on a unix box. The code used to do the uploading is C# 3.5. The system currently supports a workflow where after a threshold is met a new subfolder c...

How could I read a very large text file using StreamReader?

I want to read a huge .txt file and I'm getting a memory overflow because of its sheer size. Any help? private void button1_Click(object sender, EventArgs e) { using (var Reader = new StreamReader(@"C:\Test.txt")) { textBox1.Text += Reader.ReadLine(); } } Text file is just: Line1 Line2...