Click here to Skip to main content
15,881,413 members
Everything / General Programming / File

File

file

Great Reads

by Tomaz Koritnik
TmStorage is a structureless virtual file system from which complex storages or databases can be built.
by Mark Pelf
Beginner’s tutorial on PE format, with illustrations
by Lodewijk Pool
A quick and easy way to direct Java System.out to File and to Console.
by Mikhail-T
How to convert string to text file and return it back to user as a result of a controller action

Latest Articles

by Mark Pelf
Beginner’s tutorial on PE format applied to .NET assemblies
by Mark Pelf
Beginner’s tutorial on PE format, with illustrations
by Michael Sydney Balloni
See how Rust stacks up against C-ish, C++, and C#
by Andreas "PAX" Lück
Investigation of PE file modifications performed by Microsoft Detours

All Articles

Sort by Score

File 

23 Apr 2013 by Ian A Davidson
I am sorry that I only saw this question today. I have a several years' experience with FileSystemWatcher (and with the Win32 API functions when using C++ before C#).These are the main areas to look out for:1) As you said, make sure the code that handles notifications is as quick as...
21 Nov 2014 by Tomaz Koritnik
TmStorage is a structureless virtual file system from which complex storages or databases can be built.
10 Mar 2023 by Mark Pelf
Beginner’s tutorial on PE format, with illustrations
17 Jan 2012 by Lodewijk Pool
A quick and easy way to direct Java System.out to File and to Console.
19 Jul 2013 by Mikhail-T
How to convert string to text file and return it back to user as a result of a controller action
26 Mar 2013 by Andreas Gieriet
Change your code as follows:1) Give the Mutex the name @"Global\MyMutex".2) Call Dispose() on w after (or instead of) Close().Do the same for your other process.[EDIT]I would simplify the code as follows:public class Log{ public static Mutex m_Mutex = new Mutex( false,...
5 Mar 2014 by OriginalGriff
"it means we can't decide when it return -1 and when success?"No, you can't - that's the whole point.Think of it this way: you want to open a file so you can write some stuff into it, so you call the method to open the file. If the file is already open because some other program is writing...
1 Jul 2019 by Lance Roberts
A tray utility for monitoring log files and popping up error messages
14 Feb 2011 by Sergey Alexandrovich Kryukov
The FileDialog classes are not designed this way.The only way I can see is writing your own specialized control which does not allow to move out of initial property in principle. Doing so is easy enough. It could be based in System.Windows.Forms.ListView.The files should be listed using...
26 Apr 2011 by OriginalGriff
It's quite simple.Client: runs javascript, shows HTML via browser.Server: runs C#, sends HTML to client.When you execute Process.Start on the server, it executes on the server. And that is where Notepad will open. And that is probably where your web server administration person is...
8 Apr 2016 by V.
Convert FITS file to known image formats and use those images for a "zooming" functionality (image transparency)
10 Mar 2023 by Mark Pelf
Beginner’s tutorial on PE format applied to .NET assemblies
4 Jan 2011 by OriginalGriff
Yes it can be done - I believe, I haven't tried it (I don't have many 2Gb files lying around, and those I do I don't particularly want to but together)The problem is that you are trying to do it in a single chunk, via File.ReadAllBytes, which is (understandably) limited to 2Gb.If you...
14 Feb 2011 by Espen Harlinn
Take a look at FileDialog.HookProc[^]A bit more in the way of documentation here:http://msdn.microsoft.com/en-us/library/ms646931(VS.85).aspx[^]This should allow you to detect when the user changes directory, so that you can change it back to your preffered directory.I suspect that...
17 Feb 2011 by Orcun Iyigun
Well in 2 lines of code you can do that assuming you have acrobat reader installed in your computer. System.Diagnostics namespace has a process class to do this.add using System.Diagnostics;Place this code to your button click event.string pdfFileName =...
21 Sep 2011 by AspDotNetDev
The read-only attribute and similar attributes are part of the meta-data for the file. They are stored by the operating system and cannot be found in the file data.Text files don't typically actually have an end of file character (or sequence) stored in the data. You know where the end of...
23 May 2012 by Mohammad A Rahman
Directory.Dele...
21 Jun 2012 by Manas Bhardwaj
Use the Multiselect [^]property and loop through the FileName list. Something like this. The code is in C#, but should give you an idea.OpenFileDialog dlg = new OpenFileDialog();dlg.Multiselect = true;if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK){ foreach...
8 May 2013 by Richard C Bishop
You need to either escape the "\" like this:"\\"oradd an "@" at the front of the string. You have it done with several other string file paths on your page.
16 Oct 2013 by Sergey Alexandrovich Kryukov
The event-oriented approach does not look like some code is "telling" you what happened. The technology is much better: you use event handlers to handle events. Please see:http://msdn.microsoft.com/en-us/library/ms973905.aspx[^].Now, how to handle the events you are interested in? This is...
22 Feb 2015 by Sergey Alexandrovich Kryukov
I was afraid that my suggestion to "think a bit" could possibly offend you a bit, so I probably have to illustrate what this thinking could mean.Suppose you have some bit data, which tells you (forget the "format", it is irrelevant):you have width = 3, height = 2, and pixels data...
16 Sep 2015 by Sergey Alexandrovich Kryukov
One way to preserve some file from modifications or deletion, regardless of privileges, is to keep it permanently open in some process, for non-shared access (which is the default). To keep this state permanent, the code should also be executed permanently, which is possible if this process is...
10 Mar 2010 by «_Superman_»
fstream is a C++ object. It will work in any OS.Win32 APIs will work only in Windows.fstream implementation in Windows will eventually call the Win32 APIs.So the first approach will give you portability.The second approach will execute slightly faster.
18 Oct 2010 by shakil0304003
You can hit a page & this page can get the xml data to the flash. Every time you hit the page, you can send the current date time as parameter. So, every time the page url will be different & browser can not cash it.
4 Jan 2011 by Manfred Rudolf Bihy
You have to read the file you want to append to the other in smaller chunks inside a loop. There is a limit of 2GB for one process (at least on 32bit machines). So if the function were to read the whole 2GB at once the process would run out of memory.Besides that: fSource is a bit misleading...
11 Mar 2011 by Espen Harlinn
I believe you may find this interesting:http://www.boost.org/doc/libs/1_46_0/libs/filesystem/v3/doc/tutorial.html[^] - it will even work on other os'esYou can also usehttp://www.boost.org/doc/libs/1_46_0/libs/regex/doc/html/index.html[^] to facilitate quite advanced search...
14 Aug 2011 by mbue
You must not do that, the windows file cache works very well.Otherwise you can use FileMapping objects to share memory among different processes.(i assumed youre using windows)Regards.
19 Oct 2011 by fjdiewornncalwe
You could do this in a couple of different ways.The best would be to create the appropriate regular expression to clean the data as you want it, but another solution could be to do the following and then just add in a check for non-numeric characters in each column: I found this...
6 Jun 2012 by Dave Kreskowiak
You're using a DataAdapter to fill a DataTable from the SQL database, and you expect the system to hold over 6,000,000 records IN MEMORY?? How big is a single record?? Do the math...A more appropriate way to do this would be to create a SSIS (SQL Server Integration Services) job to export...
21 Jun 2012 by Tim Corey
The quick answer is that you need to set the MultiSelect property to true. Then the user can select multiple files and you can loop through them and copy them to the other location.Here is a question similar to yours with the correct answer...
15 Aug 2012 by Sergey Alexandrovich Kryukov
Please see my comment to the question, where I explain why it is not valid. If your files are already served up by some HTTP server, you need to access to the file using some client side. Generally, you can only download files. Uploading is only possible if the server supports it; usually it...
29 Aug 2012 by AmitGajjar
Hi,Length property should not called for the directory. if you call FI.Length for directory it will gives you FileNotFoundException.Refer MSDN for FileInfo.Length[^]Thanks-Amit Gajjar
22 Jan 2013 by GLolita
I don't need to make a whole ajax post , I just need to create an iFrame that will enable me to get the response$('#ActivateBtn').click ( function () { var SocietyNameTBxvar = document.getElementById(""); var...
13 Aug 2013 by CPallini
To fix your problem you may add a forward declaration to the files class, namely:class files; // forward declaration of the class 'files'class linklist{ files *f; // ..
4 Sep 2014 by ASP.NET Community
Here is a simplified class to create Excel file from DataTable just Pass DataTable and Preferred location on server to generate. Call the
21 Nov 2013 by nv3
Your input file does probably consist of multiple line, each containing a username and password (probably encoded with a hash function). So perform a loop over the lines in your username.txt file. In each loop iteration:a) extract the username and password out of that lineb) compare the...
17 Dec 2013 by Maciej Los
This is quite often asked question. Please see my past answer: How to get sql tables columns in excel sheet after click button in c#[^]Have you read Code Project Quick Answers FAQ[^]? Probably NOT. Next time, please use SearchBox[^] at the right-top corner on this site.
13 Feb 2014 by OriginalGriff
If in doubt, Google: ".DO Extension"[^]It found this: http://filext.com/file-extension/DO[^]
24 Aug 2015 by CPallini
Quote:while(f1!=NULL && f2!=NULL)This is NOT a good stop condition while reading files. When the end-of-file is reached, its FILE pointer doesn't become NULL. The end-of-file condition is signaled by the getc() return value being EOF (see "getc" ). Change fromQuote: while(f1!=NULL &&...
3 Jun 2016 by PIEBALDconsult
A C function that merges the content from an arbitrary number of text files into a Character-Separated-Variable-Width result file
29 Feb 2016 by Dave Kreskowiak
You can't do that. First, when the administrator password changes, your code is going to break. Second, are you REALLY going to put an admin level password into a file in PLAIN TEXT? What kind of security is that?!?!?!You either put the manifest file in there with the requestedexecutionlevel...
2 Jul 2018 by Jochen Arndt
The full error message contains more information: the name of the source file and the line number. Inspect that line and the preceeding lines, or show us the full message and indicate the line in the posted code. However, your posted code snippets should result in an error in the aliens class: ...
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(); ...
16 Jul 2020 by KarstenK
You are counting the wrong numbers. This works for characters int table[26] = {0}; // get a valid characters (exclude spaces and numbers) char c = toupper(buffer); int index = c - 'A'; table[index]++; Use the debugger to see the details.
16 Jul 2020 by CPallini
I've fixed your code (to same extent: it should work, but, as it stands, it neither particularly robust nor efficient). Try #include #include #include #include #define tab_size 26 enum { TABLE_SIZE =...
14 Oct 2021 by Dave Kreskowiak
Look at what you appear to be doing: String phoneNumber = ""; String textMessage = ""; FileInputStream excelFile = new FileInputStream(file); Path sourcePath = Paths.get(String.valueOf(file)); Path targetPath =...
17 Dec 2011 by Ragheed Al-Tayeb
Hi Olivier,First, thank you for your helpful post here and I'd like introduce some suggestion that might help to increase the performance of the Read & Write methods (of arrays such as ReadIntArray, ReadFloatArray and WriteIntArray, .... etc.). My suggestion is to make use of the...
22 Jan 2010 by Christian Graus
Sadly, I can't delete this, so I'll just say, I want to do all sorts of things. When I REALLY want to do something, I get the tools I need, and do some research into how it's done. Then, if I get stuck, I find people who know more than me, and I'll ask them in a way that makes clear that I've...
7 Feb 2010 by Graham Breach
GMail's attachment upload uses Flash to find the size and display the progress.Here is another one that does the same thing: SWFUpload[^]
11 Feb 2010 by AR@JR
swfupload is doing the job just the way i wanted it...thanks a lot
6 Mar 2010 by Alan N
Add the line fsw.SynchronizingObject = this; when you create the FileSystemWatcher. This will ensure that the events are raised on your Form's thread and the cross thread error will disappear.Alan.
11 Mar 2010 by Emilio Garavaglia
They have two different philosophy with a certain area of overlap.fstream implements the "concept" of C++ stream when the data flow are directed to files.It does so by cooperating with a number of other classes like strembuff and locales, whose defaults do almost nothing, but you can...
3 Apr 2010 by Not Active
If you mean how to get the files to display in the help file viewer, like standard F1 type help, then there are no tags to use. You must compile the the file to a chm format.http://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help[^]
5 May 2010 by fdkhb
Hello, I am looking forward to create a property page like CFileDialog's interface(listing files and selecting folders), but not intend to use shell ctrl. There are some suggestion to handle it by subclasswindow method, but I don't know how to do it exactly. So hope for your help. Thank you!
11 May 2010 by Moak
From reading MSDN[^] I don't think select() on Windows supports file descriptors... only sockets. This is unlike Linux[^] where select() works with files, pipes, sockets, etc...Hope this helps! :)
6 Jul 2010 by TickyTacky
Hi everybody,first of all I'm sorry about my poor english, as I am from Germany. I please you to excuse that.My Problem is, I'm trying to send a file via a Socket from one Computer to another. The Sockets aren't connected to each other, but to a Proxy, which handles the Communication....
23 Sep 2010 by Abhinav S
The advantage of @-quoting is that escape sequences are not processed, which makes it easy to write.As an example, I cannot use \ in my string as it is an escape sequence.So I need to use a \\ which essentially means a single "\" in C# (when compiled).Instead I could use the @...
3 Nov 2010 by JF2015
This is a batch script that can be used for scripting in windows.See here:http://en.wikipedia.org/wiki/Batch_file[^]
30 Dec 2010 by creizlein
I have been dealing with an issue for the last couple days and, despite the fact that long nights of read and debug didnt help, i wasnt able to resolve for myself, so im asking for a little help on this.Its related to icon association files, and first of all i must apologize if my english is...
4 Jan 2011 by Tony Richards
Have you tried opening it with an appropriate Windows API function, instead of the built in File functions. These may not have the limit imposed (or may have a documented way around it). I suggest you have a look through the Windows API documentation, find a function that may work, and then...
31 Jan 2011 by Manfred Rudolf Bihy
I've just taken a look at the project page at sourceforge.net and it seems to me that there isn't much development going on in recent times for Report.NET. I don't know if you need this for a commercial product or not, but please have a look here: http://itextpdf.com/[^]. For commericial use...
9 Feb 2011 by JF2015
This could be done by providing the full path to the executable that you want to refer to. So instead of "openvpn" you could say "C:\Program Files\YourApp\openvpn".
23 Feb 2011 by Manfred Rudolf Bihy
Since lucene is originally an Apache java project it's always a good idea to also look there for specialized information: http://lucene.apache.org/java/2_4_0/fileformats.html[^] This page describes pretty well what files there are and some of the content.Hope this helps you!Regards,
24 Mar 2011 by Sergey Alexandrovich Kryukov
In addition to Richard's Answer: there is no such thing as "open file in console". You just open a file, use System::IO::StreamReader as you need just to read it.If you need content comparison at the level of Microsoft Word document, this is a separate issue. Start from here:...
15 Apr 2011 by Jeffrey Enzo
Home.aspx is not default in the IIS Default Docs. You must define this!http://www.iis.net/ConfigReference/system.webServer/defaultDocument[^]
11 May 2011 by Wonde Tadesse
Well, you were trying to save the file in absolute path. But if you need to save it relative path, you need to create a folder in your web site or you need to use your root folder of the web site. I put some code snippet that may need to look it.string path = Server.MapPath("~");// Maps the...
2 Jun 2011 by Pete O'Hanlon
If you use SharpZipLib[^], you can use the following extension method:public static void UpdateZip(this ZipFile zipFile, List files){ zipFile.BeginUpdate(); foreach(string file in files) { if (File.Exists(file)) { zipFile.Add(file); } } ...
7 Nov 2011 by Danyvaral
i am creating windows application in C# in which i want to write in a multiple file with multiple threads.I am getting data from different ports and there is one file associated with every port.Is it possible that creation of thread for every port and use the same thread again and again for...
9 Nov 2011 by member60
refer:http://devssolution.wordpress.com/2011/08/23/html-to-excel-in-asp-net/[^]
10 Feb 2012 by Jochen Arndt
This is your home work. So nobody will do it for you here.However, I have one tip for you:Compile your code. The compiler error messages will help you to locate most of your problems.
23 Apr 2012 by ashkan sirous
Dear Experts,I have a from that uploads files to data table(in session) and then after clicking on send button it calls a webservice dynamically and uploads the file to data base.I've set the request length and etc for both application and webservice to 2GB:
1 May 2012 by Richard MacCutchan
1. For reading documents you should use the Word Object Model[^], or the Interop.Word namespace[^].2. Just about every database can be accessed from Windows programs - nothing to do with Visual Studio - more the database engine. There are plenty of articles[^] here on CodeProject to help you.
11 Jul 2012 by OriginalGriff
:laugh:Tha...
23 Jul 2012 by fjdiewornncalwe
You are attempting to delete the file that was read in within the thumbnail object. Perhaps if you disposed of the thumbnail object, the file resource would be released.
29 Aug 2012 by Zoltán Zörgő
Read here: http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.selectedpath.aspx[^]Quote:The path of the folder first selected in the dialog box or the last folder selected by the user. You probably need a file to upload. Folder length has no meaning in this context.
16 Nov 2012 by Espen Harlinn
ImageMagick would do the trick, have a look at:ImageMagick: Convert, Edit, Or Compose Bitmap Images[^] and Magick++ C++ API[^] - it's a great package.Best regardsEspen Harlinn
19 Dec 2012 by Christian Graus
You mean 'about internet explorer' ? It's just generated by code in the exe. If you mean an about page that a site has, it's HTML on the site.You can keep data in memory without writing it to the file system, but you don't want to do that for too long. If the data is being moved in real...
27 Mar 2013 by tzych
See approved solution below - because the file is being accessed from two different user spaces, the Mutex needs to be declared as Global. Thanks to Andreas for the solution!=========================OK, I have a log file that can be written to by multiple processes. I'm trying to protect...
1 Apr 2013 by OriginalGriff
You can't "delete a line" from a text file - to do this, you will have to open a new output file, and copy over the lines you don't want to delete. At the end, close all the files, rename the original to a temporary name, then rename the output file as the original, and delete the original.
9 Apr 2013 by Sergey Alexandrovich Kryukov
This is not really a "solution", but something you should better be aware of; please see these CodeProject articles:FileSystemWatcher - Pure Chaos (Part 1 of 2)[^],FileSystemWatcher - Pure Chaos (Part 2 of 2)[^].—SA
10 Apr 2013 by Matthew Faithfull
Don't bother, just use seek to return the file pointer to the beggining of the file and then write an EOF if you want to. On Win32 there's an API to set the extent of the file which you could use to prevent anything reading past that EOF even if it chose to. That's not necessary though if your...
5 May 2013 by CPallini
You program is incorrect. In order to read the written data, you have to (re)position the 'file pointer' at the very beginning of the file. This can simply accomplished by closing the file and then open it again for reading.//...pFile = fopen ( "myfile.bin" , "wb" );fwrite (buffer , 1 ,...
9 May 2013 by OriginalGriff
GetFiles does not return a =single file value - it returns an array of full paths to all the matching strings, even if there is only a single file that matches the specifications given.So you need to always hold the return value in an array of strings, and you should always check that at least...
9 May 2013 by CPallini
Your while condition is uninfluential (always true). According to the documentation[^]:Return ValueThe total number of elements successfully read is returned.If this number differs from the count parameter, either a reading error occurred or the end-of-file was reached while reading....
3 Jun 2013 by Prasad Khandekar
Hello Suma,Make sure the manifest file for your app contains following permission entries then you can use the code given below to delete a file from external storage.
3 Jun 2013 by _Amy
I agree with Prasad in Solution 1[^]. I am adding few links which will explain you about storage option in android.Storage Options[^]Android Environment[^]--Amit
5 Sep 2013 by Richard MacCutchan
Your problem is due to the Scanner class trying to interpret the tokens from the input file and convert them to bytes. You need a basic stream reader that will allow you to read individual bytes from the file.Try this:import java.io.File;import java.io.FileNotFoundException;import...
18 Oct 2013 by xmark1rax
I found a solution: Instead of %variable%, write %%variable%%.So in order to display/write one %, write ECHO %%.
14 Nov 2013 by Sergey Alexandrovich Kryukov
First of all, to work with FTP as a client, you will need to use the class System.Net.FtpWebRequest:http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest%28v=vs.110%29.aspx[^].Then you will need to use proper System.Net.FtpWebRequest.Method. Please...
15 Nov 2013 by Ron Beyer
The full path of the file that "opened" the program is available as the second (index 1) argument on the command line:Environment.GetCommandLineArgs[^]So the full path of the file is Environment.GetCommandLineArgs()(1)(Index 0 is the executable name/path).
9 Feb 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Refer - upload file directly without "upload" button[^].This thread has discussed exactly what you need. There are many accepted solutions, so follow them.
1 Dec 2014 by OriginalGriff
Use XML: it's flexible, easy to use and even (relatively) human readable: http://msdn.microsoft.com/en-us/library/ms950721.aspx[^]
21 Feb 2015 by nv3
Just exchanging width and height will not rotate the image. You also need to rotate the bitmap data pixel by pixel. That requires quite a bit of buffer handling and data shoveling. For an example how to do it, look here: Add fast user-extensible image processing support to CBitmap[^]
17 Aug 2015 by Dave Kreskowiak
Possible, yes, BUT... It depends entirely on what's in the files and the compression algorithm used. If they're nothing but text files, you might be able to get 90% out of it. If it's a bunch of JPG files, not a chance. The files are already compressed about as much as is going to be possible.
16 Sep 2015 by F-ES Sitecore
You can't create files that can't be deleted or else viruses would be impossible to get rid of. If the user wants to delete those files then your app stops working (or you can re-create fresh copies), that's their decision.
10 Dec 2015 by ridoy
You can save your textview data to a text file by this code example: File root = new File(YOUR_DIRECTORY_PATH); File gpxfile = new File(root, "yourFileName.txt"); FileWriter writer = new FileWriter(gpxfile); writer.append(yourTextview.getText().toString()); writer.flush(); ...
21 Jan 2016 by Dave Kreskowiak
This appears to be ASP.NET code which runs entirely server side. If you're expecting to get a full file path sent by the client it's not going to happen. The server will not get access to, nor should it ever care about, what path the file came from on the client.
3 May 2016 by CHill60
In the past I've approached this in three slightly different ways1. Each process had it's own folder for handling the files "owned" by that process. Files were moved from the central drop area into the processing folder, then once that process was finished the file was physically moved into...
1 Jun 2016 by CPallini
You cannot serialize/deserialize a class containing std::string that way. See, for instance c++ - Serializing a class which contains a std::string - Stack Overflow[^].
17 Jul 2016 by Andy Point
Android Download Manager Tutorial: How to download files using Download Manager from the Internet