Click here to Skip to main content
15,885,216 members
Everything / FileIO

FileIO

FileIO

Great Reads

by Michael Sydney Balloni
Different languages and approaches are evaluated for a file and string processing benchmark
by shijo joseph
A file backup manager with simple user interface and all the essential functionalities.
by Marijan Nikic
A utility for automatization of moving files from partition A to partition B and vice versa
by Marco Bertschi
The presented code snippet compares two given files using the IEqualityComparer.

Latest Articles

by Michael Sydney Balloni
Different languages and approaches are evaluated for a file and string processing benchmark
by Marijan Nikic
A utility for automatization of moving files from partition A to partition B and vice versa
by Member 13353000
How to upload images on MVC Web App razor pages using ASP.NET Core 2.2
by Uwe Keim
A .NET library to access files and directories with more than 260 characters length

All Articles

Sort by Score

FileIO 

27 Sep 2022 by Michael Sydney Balloni
Different languages and approaches are evaluated for a file and string processing benchmark
24 Jan 2015 by shijo joseph
A file backup manager with simple user interface and all the essential functionalities.
22 Dec 2019 by Marijan Nikic
A utility for automatization of moving files from partition A to partition B and vice versa
7 Nov 2014 by DamithSL
try using .NET Transactional File Manager[^]
16 Nov 2014 by Garth J Lancaster
not sure what your issue is - you could do this (separate file handle for reading and writing) :-#include main(){int t_size; FILE *fp_read; fp_read = fopen ("xxx.txt", "r"); fscanf(fp_read, "%d", &t_size); fclose(fp_read);FILE *fp_write;int a =...
16 Nov 2014 by OriginalGriff
Easy! Just create a second FILE instance:FILE* fpInput;FILE* fpOutput;fpInput = fopen ("xxx.txt", "r"); fscanf(fpInput, "%d", &t_size); fpOutput = fopen ("yyy.txt", "w+"); fprintf(fpOutput, "The int is %d\n", t_size); fclose(fpInput);fclose(fpOutput);And please: it's...
22 Jun 2015 by Dave Kreskowiak
You're making the assumption that every file that came from the site was cached.Unless the guy who setup the website was incredibly stupid, the CAPTCHA images will NEVER be cached, read: written to disk anywhere.
27 Feb 2016 by Jochen Arndt
See fopen[^]:Quote:When a file is opened with update mode ( '+' as the second or third character in the mode argument), both input and output may be performed on the associated stream. However, the application shall ensure that output is not directly followed by input without an intervening...
2 Apr 2016 by Richard MacCutchan
See Lesson: Basic I/O (The Java™ Tutorials > Essential Classes)[^] for full details on file I/O.
16 Jan 2018 by Richard Deeming
This is one of the big problems with async void methods - the method returns before it has completed, and the caller has no way of knowing that the method is still doing work. The Application class raises the Startup event. When the handler returns - at the first await call in your example - it...
28 May 2018 by Marco Bertschi
The presented code snippet compares two given files using the IEqualityComparer.
7 Oct 2019 by phil.o
You do not need to create the file before using WriteAllLines. It is possible you run into a race condition by using WriteAllLines just after Create. You could try: if (!File.Exists(filePath)) { List output = new List(); ...
10 Jan 2020 by F-ES Sitecore
Just do something simple like var CurrentBatchName = fileList.FirstOrDefault(f => f.Contains(batchperiod));
5 May 2020 by MadMyche
You can't; this is due to security/privacy concerns. What you want to do is upload the file and save it to a "temp" location. Then you do your validation routine, if it passes you then send it to the final location. There's a pretty good answer...
17 Sep 2014 by Shemeemsha (ഷെമീംഷ)
These links may helpful http://stackoverflow.com/questions/16255882/how-to-upload-image-display-image-in-asp-net-mvc-4[^]http://stackoverflow.com/questions/20446580/upload-image-included-in-mvc-model[^]@using (Html.BeginForm("Index", "FileUploader", FormMethod.Post, new { enctype =...
7 Nov 2014 by Afzaal Ahmad Zeeshan
There needs to be an exception that gets raised when there is a failure while transfering the files to the client (destination). So that would be liketry { // send all the files} catch (Exception er) { // exception was raised, // if the exception was the File Not Transferred...
9 May 2019 by Member 13353000
How to upload images on MVC Web App razor pages using ASP.NET Core 2.2
7 Aug 2020 by Richard Deeming
Something like this should work: var fileNames = directoryInfo.EnumerateFiles() .Select(f => f.Name) .ToLookup(f => Path.GetFileNameWithoutExtension(f).LastOrDefault()); listBox1.DataSource = fileNames['a']; listBox2.DataSource =...
13 Jul 2021 by OriginalGriff
The three standard streams are specifically allocated to console I/O - you dont; use them to access files at all. Instead, your create a new stream for each file using the fopen function[^] which returns a FILE * - which is a pointer to a stream....
28 May 2014 by Richard MacCutchan
Create a new fileAdd a header record identifying the first file, its type and length.Read the file, and write it to the output.Add a trailer record confirming the end of the file.Repeat for any number of files.Add en and of data record confirming no more file.Close the output...
15 Jun 2014 by DamithSL
you can use Guid.TryParse Method[^]string filename = "acd5604f-5bbd-4e94-9b40-ea0247cdb4ad";Guid guid;if(Guid.TryParse(filename , out guid)){ //delete file }
15 Jun 2014 by phil.o
The pattern is:- 8 hexadecimal digits- dash- 4 hexadecimal digits- dash- 4 hexadecimal digits- dash- 4 hexadecimal digits- dash- 12 hexadecimal digitsA regular expression could catch it easily:Regex r = nex...
28 Jul 2014 by pavanreddy61
Output is : Parent : xxxxxThe fork command actually creates a child process, and returns the PID of the process to the parent, and a value of zero to the child. In this example, the first block of code is executed by the parent, while the second block is executed by the child. The one thing...
14 Oct 2014 by ZurdoDev
To get web root you use Server.MapPath and give it the virtual path.String path = Server.MapPath("~/image_logo/ImageName.gif");will return L:\chikardarin WebSite\WebApplication2\image_Logo\ImageName.gif assuming that WebApplication2 is your root.
14 Oct 2014 by majid torfi
string filename = Server.MapPath("~/image_logo/" + ImgName);if (System.IO.File.Exists(filename)){ System.IO.File.Delete(filename); Response.Write("Deleted");}
14 Oct 2014 by Sergey Alexandrovich Kryukov
Please see my past answer on this problem: how to compress the error 'it is already used by another process' in vb.net[^].—SA
20 Nov 2014 by Fredrik Bornander
If you want to use C, something like this might work for you;#include #include #include char* append_char(char* buffer, char character) { *buffer = character; return ++buffer;}char* append_number(char* buffer, int number, char* temp_buffer)...
24 Dec 2014 by DamithSL
try to dispose the file stream when you create it first timeif (!File.Exists(logPath)) { using (_fileStream = File.Create(logPath)){}; }
24 Dec 2014 by Sergey Alexandrovich Kryukov
Don't you think that this is a very natural contradiction: with the logging mechanism, you can collect all the information which could reveal your bugs, but what if you make a bug in logging itself?Apparently, the solution is: develop and well debug logging mechanism in advance, before you...
8 Jan 2015 by Suvendu Shekhar Giri
No need to use loop. Try thischar[] arr = textBox1.Text.Trim().ToCharArray();Array.Reverse(arr);richTextBox2.Text = new string(arr);Hope, it helps :)Update:Using file read/write:string text = System.IO.File.ReadAllText(@"D:\YourFolder\file1.txt");char[] arr =...
7 Feb 2015 by Zoltán Zörgő
This is the way: http://www.html5rocks.com/en/tutorials/getusermedia/intro/[^]. But as not all have HTML5 browser, you still need some fallback, so check this too: https://github.com/jhuckaby/webcamjs[^]
19 Mar 2015 by farhad bat
//cin is wrong instead should use getline(cin, pathOfFile) . cin when read space halt reading more character but getline read full pathstring pathOfFile;//read path of file.std::cout >...
22 Mar 2015 by phil.o
The only way I can see to achieve that, apart from an index file suggested in solution 1, would be to compare datetimes of modification. All other methods (hashing, file version, etc.) require the file to be downloaded.
11 Apr 2015 by Sergey Alexandrovich Kryukov
You can only check timing before and after the click to File.Copy; you cannot hook into the middle of transfer to update partial speeds. If this is all you want, you can use the class System.Diagnostic.Stopwatch, which gives you the best accuracy:...
15 Apr 2015 by Mukesh Pr@sad
Hi Experts, here is the file structure what I am getting:-FileName ,Docname, Repeat1, Repeat2(these are the header of the file)tronox, tronoxdoc, one,tronox, tronoxdoc, two,tronox, tronoxdoc, three,expected output is:-FileName ,Docname, Repeat1, ...
10 May 2015 by Sascha Lefèvre
You find the resources in the class Resources. Given the top-level namespace of your project is called "MyProject", you find the default Resources-class under the namespace MyProject.Properties, e.g.:Bitmap image1 = MyProject.Properties.Resources.Image1;Depending on the type of resource the...
2 Jun 2015 by Sergey Alexandrovich Kryukov
Your list items should be the full names of the infected files. You don't have to show the full names in UI. To achieve that, you can create an item class (or struct) with all item information you need for your work and override System.Object.ToString. You will find more detail in my past...
8 Jan 2016 by Sergey Alexandrovich Kryukov
You don't need to find all partitions. First of all, not all partitions have file systems. Instead, you need to find all logical drives. This is how: DriveInfo.GetDrives Method (System.IO)[^].Instead of the method Directory.GetFiles, you can use another Directory.GetFiles method which finds...
28 Feb 2016 by Richard MacCutchan
You can use the FILE_OVERWRITE option on your call to ZwCreateFile routine (Windows Drivers)[^].
20 Mar 2016 by Jochen Arndt
See Bitmap Constructor (String) (System.Drawing)[^]:Quote:The file remains locked until the Bitmap is disposed.So call Dispose() before deleting the file or delete the file after the Bitmap instance has been finalized.
9 May 2016 by Suvendu Shekhar Giri
What you want to achieve through following line of code?File.SetLastWriteTime(path, new DateTime());If you want to set current datetime as LastWriteTime, try following-File.SetLastWriteTime(path, DateTime.Now);If you still experience the same error or if your requirement is something...
14 Sep 2016 by KarstenK
Here is some information about 7-zip.Use the command line tool for compressing your written files.
16 Sep 2016 by Afzaal Ahmad Zeeshan
When you open a stream to a file, you pass the location of the file (including the name) to that object. Typically, a name of the file is passed only (like, _ofstream.open("file.txt")) which creates the file in the same directory, where the program is residing. In most cases, you would require...
18 Oct 2016 by #realJSOP
0) I think your email regex is rather weak. Try this one:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?1) Why not just split the string on spaces, regex the email address, and then run the phone number...
18 Oct 2016 by Surendra Reddy V
Try this :string strval = ""; string strFormat = "abcdef sjifdjkf sjdkAaasa 122.345 11/10/2016 [u'hello@xyz.com'] 8989878787"; Regex rg = new Regex(@"[A-Za-z0-9_\-\+]+@"); strval = rg.Replace(strFormat, "_HIDE_@"); string pat = @"\d{10}"; ...
18 Oct 2016 by Patrice T
Just a few links about RegExHere is a link to RegEx documentation:perlre - perldoc.perl.org[^]Here is links to tools to help build RegEx and debug them:.NET Regex Tester - Regex Storm[^]Expresso Regular Expression Tool[^]This one show you the RegEx as a nice graph which is really...
15 Feb 2018 by OriginalGriff
Simple: don't separate items with any character which is legal in a file path. If you do, you are asking for problems, which will be very difficult to resolve. So instead of separating paths with commas, use the vertical bar character '|' as that is not allowed in paths at all: Naming Files,...
20 Sep 2018 by SaiChanderMG
Hello, Ur code needs to be changed a bit as it is not following the logic u want. I am just trying to modify ur code in such a way that it follows the logic u need. Solution can be more simplified but I don't want to do as it wont explain what you are missing exactly. Old Code: modification...
27 Oct 2018 by Rick York
If I were you, I would do make a little set of functions to deal with your data structure. It will clean up the code A LOT! I think you will be able to see logic errors much easier. Here are some examples :int ReadRecord( details * pd, FILE * pf ) { char a[512] = { 0 }; int i = 0; ...
10 Jan 2020 by phil.o
string period = "55"; var batchperiod = period.ToString(); Why are you doing this? Calling ToString() on a variable which already is a string just does not make any sense. Moreover, Enumerable.SingleOrDefault Method[^] throws an exception if there is more than one element in the sequence. Which...
10 Jan 2020 by OriginalGriff
Try: string batchperiod = "_55_"; string BatchInPath = @"C:\Users\myuser\source\repos\MySolution\MyProject\BatchIn"; IEnumerable fileList = Directory.EnumerateFiles(BatchInPath); var CurrentBatchName = (from file in fileList let fileName = Path.GetFileName(file) ...
28 Jan 2020 by Maciej Los
I'd strongly recommend to read this: Development-time IIS support in Visual Studio for ASP.NET Core | Microsoft Docs[^] and this: Publish to IIS by importing publish settings - Visual Studio | Microsoft Docs[^] You need to understand (what has been already stated in the comments) that accessig...
6 Feb 2020 by OriginalGriff
When you posted this yesterday: Can not replace word in file using C language[^] I told you that you need to use the debugger to work out what your code is doing, and from that you should be able to work out what you need to change: that doesn't change because it's Friday instead of Thursday! ...
8 Jul 2020 by OriginalGriff
Use C library function - fseek() - Tutorialspoint[^] But how many times have we told you now that you are doing this the wrong way?
24 Jul 2020 by Patrice T
Quote: My program works perfectly for smaller files. Is there any way to make my code better? If you don't want magic answers, the first thing to do is to understand how the program spend time and why. The tool of choice is the profiler....
24 Jul 2020 by KarstenK
The code looks good, so optimizing the existing code may only helps little, but you may change your word storage like in a balamced binary tree which improves the search speed. Using some hash key of the string as sort criteria is always a good...
7 Aug 2020 by Member 11396175
Hello friends !!!!! I have one folder with many txt files with filename 11111111111_a,11111111111_b,22222222_a,22222222_b How can separate to 2 listboxes by last digit? What I have tried: private void Form1_Load(object sender, EventArgs e) {...
7 Aug 2020 by TheRealSteveJudge
If your filenames are like this e.g. 11111111111_a.txt or 11111111111_b.txt LINQ will help you. listBox1.DataSource = shortFilenames.Where(x => Path.GetFileNameWithoutExtension(x).EndsWith("a")).ToList(); listBox2.DataSource =...
22 Dec 2020 by OriginalGriff
Depends on the language you are using, but basically it's the same as you would do manually: 1) Read lines until you get one starting "CV ". When you find it create a new collection to hold the lines you wanted (or empty any existing collection)...
13 Jan 2023 by Richard MacCutchan
Your fwrite call parameters are incorrect: fwrite(name, sizeof(name) , sizeof(name) , fptr); That means you will try to write 50 characters 50 times. It should be: fwrite(name, sizeof(name) , 1, fptr); // write the name once only And the...
3 Dec 2022 by George Swan
I would go for the simplistic approach. Something along these lines: IEnumerableitems=lines.Select(l => { var array = l.Split(':'); var player = array[0]; var cards = array[1].Split(','); return...
9 May 2014 by DamithSL
ReadAllText Opens the File, Read the text, then close it. If another thread or program try to open the same file while ReadAllText reading, Then YES, you will get exception
22 May 2014 by Member 10834545
I am working on an application that should read a text file which contains the path of the .jpg files using C file handling functions.The requirement is to read the file line by line but if the path of the line is wrong, it should not read the current line any more and should move into the...
4 Jun 2014 by Adrian71
I need to transfer file to remote machine,i am trying it using impersonation,if possible please suggest an alternate way to do so also.
5 Jun 2014 by Thakkar Vipul
Can you try this please??http://stackoverflow.com/questions/295538/how-to-provide-user-name-and-password-when-connecting-to-a-network-share[^]
7 Jun 2014 by Member 10870699
I get segmentation fault when i read for the second time from the fifo in the infinite loop.I don't understand why and if i don't call the function servi(...) that creat a new that send data to client i don't get a segmentation fault.I really don't understand why.This is the code.#include...
7 Jun 2014 by leon de boer
I am stunned that code even compiles ... can I ask what compiler allows this?Lets start with what won't even compile and shouldn't compile on most compilers and maybe compiles on your compiler but I am not sure what the hell it would compile and may be the source of your error. I have...
10 Jun 2014 by orgilhp
I have a c# code to copy image to specific folder just as simple as below:string fileName = "image.jpg";string source = "c:\photos\" + fileName;string destination = "\\172.16.242.41\photos\" + fileName;File.Copy(source, destination);Problem is: destination is shared folder on Server...
10 Jun 2014 by DamithSL
you can use this small C# Class for impersonating a User[^]and copy file as below using ( new Impersonator( "myUsername", "myDomainname", "myPassword" ) ){ // code that executes under the new context. File.Copy(source, destination);}Additional reference:Connect to a UNC...
10 Jun 2014 by orgilhp
Pls show me a sample of DomainName.DomainName is "\\172.16.242.41\photos\" for my case, right?
15 Jun 2014 by Tarek Elqusi
due to some code many files of the form "acd5604f-5bbd-4e94-9b40-ea0247cdb4ad"have been created in some of the clients' folders. These files are created using some GUID() function and they have no extension.I needed to remove them, what is the pattern that helps getting them in the...
17 Jun 2014 by sid2x
Hello,I'm trying get "tokens" from a file under C, into a preallocated buffer. So far it looks like this: char* token;....int main(int argc, const char* argv[]){ .... token = (char*)malloc(256); grab_token(); ....}void grab_token(){ char a; int i =...
17 Jun 2014 by CPallini
You are using OR (||) where you should use instead AND (&&).You are not checking for buffer overrun on token (actually you are not checking even if malloc succeeded).
17 Jun 2014 by Vedat Ozan Oner
CPallini is right. But to be more clear, see the following piece of code. It includes some comments and advices. you can change it according to your needs. I haven't tested the code, but I think there won't be any core dump (if it compiles successfully :) ).// define size as...
23 Jun 2014 by Dineshkumar Ramakrishnan
How to save and retrieve file ( text / image ) from SQL Server Database using PHP?Hi i supposed to save and retrieve files ( maybe image ) into SQL Server Database using PHP using VARBINARY(MAX) DataType.
29 Jul 2014 by Member 10978878
I have the following code that is giving me a Huge problem, and cant seem to figure out why.I stored some information to a file and i want to read it out back but it keeps on reading out 9 variables instead of the 14 and i dont know why.Reading out code ( i have left out some of the code...
10 Aug 2014 by hari111r
Hi All, I want to write larger (50mb)bytes to file for download log purpose in my application. I am getting out of memory exception some time. To avoid Out of memory exception i googled and find the below code.using (StringReader file = new StringReader(result)) { ...
10 Aug 2014 by CB Sharma
Hello May be below link help you.http://stackoverflow.com/questions/955911/how-to-write-super-fast-file-streaming-code-in-c[^]
12 Aug 2014 by Sharmanuj
Follow these steps to achieve the same1. On click of upload file read the .csv file and store the data into DataTable. for example 200 columns with 100 Rows2. On click of button "Create user" Send this datatable to the form which will display all the users list which needs to be...
12 Aug 2014 by yasir20
there is many ways to insert file records in database 1. create file csv or text file with comma or pipe separated ,whatever you want 2.read that file by coding and read row n column wise record3. create Datatable with column and add the file recorded value in dataTable4. Datatable set...
31 Aug 2014 by Karim Pazoki
I write below code for write something in a file that uploaded in a url. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://domain/filename"); HttpWebResponse Response = (HttpWebResponse)request.GetResponse(); Stream...
27 Sep 2014 by Narendra Singh
Hello I have developed a webpage where i need to upload a image of user . I wrote code for that and tested it on local server. But when i uploaded it on server it giving exceptionSystem.UnauthorizedAccessException: Access to the path 'C:\Inetpub\vhosts\pspl-it.com\site1\projects\SBI -...
27 Sep 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
This is due to the permission issue for that folder in server.Please assign proper permission to the folder by going to its properties. Search the issue in Google for more information.
14 Oct 2014 by Member 11125813
Hi , I upload a file like below.File_Upload.PostedFile.SaveAs(Server.MapPath("L:/.../a.jpg"));And i would like to delete my file with the below code.System.IO.File.Delete("L:/.../a.jpg");I faced to this error : The process cannot access the file 'L:\chikardarin...
18 Oct 2014 by Member 11125813
Hi all . i have 2 buttons one of them upload an image and another delete it . In my code there is an also which as soon as upload image asp:image show that image and after deleting image should disappear from the form .my add button has the below code : protected void...
19 Oct 2014 by Sergey Alexandrovich Kryukov
This is not a question, this is a request to do your work. Sorry, this is not a site for development of software project on your order.—SA
7 Nov 2014 by frostcox
Hey guys, I have a scenario in my application where I need to transfer 20 files from a source location to a destination location (all local transfers), if one of the files fail to transfer, for whatever reason I need to roll back a transaction so that all the file remain in the source location...
20 Nov 2014 by Richard MacCutchan
Slightly simpler than Fredrik's solution:#define MAXIMUM 10//00000int main{ FILE* fp; int count, number; char szNumber[16]; fp = fopen("testfile.txt", "w"); for (count = 1; count
24 Dec 2014 by B. Clay Shannon
I've got a log file that's created, if it doesn't exist, the first time it is referenced: if (!File.Exists(logPath)){ _fileStream = File.Create(logPath);}Yet if the file doesn't exist, the app will crash with the overly generic exception msg, "Application bla...
8 Jan 2015 by neveen neveen
I have this code to reverse message entered from textBox and then show the result of reverse in another textBox ,how can using file the first file have the message and other file print in it the result of reverse for (int i = textBox1.Text.Length - 1; i >= 0; i--) { ...
21 Jan 2015 by radnix
Greetings, I'm using C++ DirectShow and also C# DirectShow.Net to try to process and display MPEG-2 TS (Transport Stream) video files. These videos do play with VLC. I've been successful with video file types *.avi, *.wmv and *.mpg (type-1) but fail on Mpeg-2 TS. Does anyone...
31 Jan 2015 by BirjuGohel
I have Create a Web ServiceAnd Android Side Upload File (And Video file Part in multiparty and send Android Application Multiparty file and File name )Android Request send two Parameter in asp.net web service,So How to Store Server Folder in Video File Asp.net Web service...
3 Feb 2015 by Member 11425895
hello, i have a file named "sxase" in my home directory.on checking the properties i find that the file type is ".mp4".i am looking for a java code that can tell me the extension for the file name "sxase".As i am working on the project that involves implementation of this code too i dont want...
4 Feb 2015 by Richard MacCutchan
File type is just an extra few letters on the name, e.g. thistextfile.txt. It has no real meaning beyond being a useful visual aid for the system user. If you want to show all types in Windows explorer then select the Folder options in the Tools menu item, and uncheck the selector titled "Hide...
6 Feb 2015 by anurag.netdeveloper
Hi All, I would like to know if there is a way by which i can read/capture some specific data from a static mainframe screen.I mean can i read data at some specific position (pixel).Any help will be greatly appreciated.--Thanks & Regards,Anurag Malani
7 Feb 2015 by Mr_cool
Please let me know if somebody knows a way out to record a video from the webcam and then upload it to the server. This needs to be done for web application using asp.netAny help will be appreciated.
8 Feb 2015 by User 11197367
Hi guys.I have currently a little Problem, because the System doesn't recognizes a Path that ends with a backslashI'm trying this here, but it has no affect on the argument args[0] = args[0].TrimEnd(Path.DirectorySeparatorChar);thanks.Sincerely:Jonas
8 Feb 2015 by OriginalGriff
"the System doesn't recognizes a Path that ends with a backslash"Yes, it does: It says "this is a folder". static void Main(string[] args) { string[] files = Directory.GetFiles(args[0]); foreach (string s in files) Console.WriteLine(s); ...
9 Feb 2015 by A.Castillo
You can try this, too: check the homepage of Ozeki Camera SDK . Here you can find solution to record the video of your camera. And after you made it you can upload to the server, it support ASP.NET.