system.io

Is there an easier way to reconcile a list of files and a directory with subfolders/files to find changes?

I have a SQL Server table with a list of files (path + filename), and a folder with multiple layers and files in each layer. I'm looking for a way to reconcile the two without having to process the list twice. Currently, I'm doing this: For Each f as FileInfo In FileListFromDatabase If f.Exists is False, mark it as deleted in the dat...

What is the difference between File.ReadAllLines() and File.ReadAllText()?

What is the difference between File.ReadAllLines() and File.ReadAllText()? Thank you very much. ...

Parallel.For System.OutOfMemoryException

We have a fairly simple program that's used for creating backups. I'm attempting to parallelize it but am getting an OutOfMemoryException within an AggregateException. Some of the source folders are quite large, and the program doesn't crash for about 40 minutes after it starts. I don't know where to start looking so the below code is...

GetFiles() returning 0 files on NetWare/NSS

Hi, I am trying to run GetFiles() and it is returning 0 files on NetWare/NSS file system. The file is definitely there. Is there some other code I can run on this file system. The same code runs fine if it is run on a Windows Server. string[] s = System.IO.Directory.GetFiles(Environment.CurrentDirectory, "file.txt"); bool exists= s.Len...

Way to get unique filename if specified filename already exists (.NET)

Is there a built in .NET function to get a unique filename if a filename already exists? So if I try and save MyDoc.doc and it already exists, the file will save with name MyDoc(1).doc, the same way a browser download works for example. If not, what is the most efficient way to achieve this result? I am using the File.Move function at ...

Can I tell if a string corresponds to either a file or a directory in .NET?

If I have a string, I know I can use If System.IO.File.Exists(mystring) or System.IO.Directory.Exists(mystring) to see which it is. Is there a method I can use to make a single call to determine which type it is? Since, at least in Windows, you can't have both a file and a directory with the same name, it seems like there should be a fun...

Please confirm change in path length related behaviour in .NET 4.0

Hi, can someone confirm that microsoft changed path length related behaviour of some classe from System.IO in .NET 4.0? For example the code below runs fine on .NET 3.5 but on 4.0 throws a PathTooLongException for me. const string prefix = "C:\\"; const string suffix = ".txt"; var sb = new StringBuilder(); sb.Append(prefix); for (var ...

CSV file creation without exponential numbers

Hello Everyone, How do you get around the exponential conversion that takes place when inserting a value into a csv file. I have a process that creates a csv file and then starts entering rows into it. One of those fields inside a row inserts a value similar to this: 123,45,45,466,6656,23423,2455,234,2454 These are just a string of i...

Is it possible to read-lock a file?

I'm developing an application which checks for changes made to a file by a separate program (not written by me). If a change is detected, it opens the file, reads the last line, then closes the file. I'm using the following code to make sure my program doesn't try to lock the file, but only opens it in read mode: FileStream fs = n...

Get directory where executed code is located

I know that in the same directory where my code is being executed some files are located. I need to find them and pass to another method: MyLib.dll Target1.dll Target2.dll Foo(new[] { "..\\..\\Target1.dll", "..\\..\\Target2.dll" }); So I call System.IO.Directory.GetFiles(path, "*.dll"). But now I need to get know the path: string pa...

System.IO.FileInfo throwing access is denied exception to a local file

I created a sample Silverlight Web project and I am getting 'Access is denied' when I do this: string fileName = "map.gif"; FileInfo fileInfo = new FileInfo(fileName); How can I give the web project access to this folder/file? I added the image into my project, really drawing a blank here.... ...

system.io.ports using rtsenabled receiving wrong packet

i am writing a method which sends a particular packet and gets an answer back from an electronic device. I am using system.io.ports with rtsEnabled = true. The problem is that when entering the application the received packet is altered. I am monitoring what is being received using eltima and the packet received by eltima and that by...

How Make A Text File In Memory And Write Something On It And Open NotePad In Client And Open That File In It?

Hi My Dear Friends : How can i Make A Text File In Memory(Ram -> Save NoWhere) And Write Something On It And Open NotePad on top of Client browser And Open That Text File In It And Let the user save it by him/her self? -> in code behind thanks in future advance best regards ...

File.Delete failing when Image.FromFile was called prior it, despite making copy of loaded image and destroying original one

UPDATED I used below solutions (loading Image from stream), but get new problem. img object is absolutely correct Image class instance with all field filled with correct values. But calling img.Save("path/to/new/image.bmp"); on it results in new exception for GDI+ (System.Runtime.InteropServices.ExternalException, in GDI+ interface) ...

C#- What is the best way for write text to a file from array of strings.

Group, I'm looking for new and fun ways to write an array of strings to a .txt file. -This file will be rewritten every time its called and saved. -The file name will be dynamic enough that the .exe will know what string goes where. For example: ~/someFile.exe "fileName" "string|string|string|" -In this example someFile.exe is ca...

ASP.NET System.IO.File.Open("C:\TEST.TXT", System.IO.FileMode.Open); ERROR FILE NOT FOUND? LOCAL:

Dumb question.. is this c# code intended to read local client files? System.IO.FileStream content = System.IO.File.Open("c:\test.txt", System.IO.FileMode.Open); It gives me error FILE NOT FOUND I'm running Windows 7 and IE 8. ...

File.Exists() and File Access Synchronization across processes

I have a couple applications running in separate processes that each write to a central xml doc on the harddrive. I am using a named mutex to synchronize access to the file - but get the following exception often: System.IO.IOException: The requested operation cannot be performed on a file with a user-mapped section open. I realized ...

System.IO.Path.GetTempPath() access denied

Hi, im creating temporary files to be stored in the Temp folder found by: string path = System.IO.Path.GetTempPath() method returns C:\windows\Temp\ i append my filename: string filename = myfile.txt System.IO.Path.Combine(path,filename) However, this gives me a "Message":"The given path\u0027s format is not supported.","StackTrac...

change the system.io.port datareceived event output type

Hi there, I am building a class library for modbus and serial connections, I need to return an array of bytes back but when using the DataReceived event from System.IO.Ports I cannot return any since it's type is void. Also I am noticing that the DataReceived is not firing. The following is my code: public void ConnectSerialModB...

Reading a file opened from "Scanners and Cameras" throws UnauthorizedAccessException

Our application requires a user to select a photograph from their camera. The cameras I tested with while adding this feature would all appear as a drive letter in "My Computer" so loading and working with the image was a no-brainer. A coworker gave me his camera which rather than mount as a drive it triggers the awful "Scanner and Cam...