Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
How can I check if a file that is in a directory is a CSV file without checking its extension?
If the file extension is not a mandatory for your program design, but only format of the file (csv in your case), the only valid way to check if a given file is either "ok" for you or not, is simply to check your data structure after you populated it from the file.
The basic flow in gross may look like this:
1) Select file
2) Read the file
a) Exception happens somewhere = non valid CSV formatted file
b) All is ok
3) Validate datastructure(s) populated from the file
a) Some mandatory fields are not initialized = non valid CSV file
b) All is ok
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to read a file in binary and create a file of the same format with that binary, this file can be in any commom format like (.docx, .txt, .jpeg, .png ) etc.
I created a text file (test.txt) that has a string This is a text string written in it.
string file = "filelocation"; //this has a file location
byte[] data = File.ReadAllBytes(fileWithExt); // this gives me binary data.....
Now how do i create a file of the same extension with the binary data. ?
Per comment feedback, this is more about encryption than just binary file I/O.
Encryption can be done on a file after it is already saved:
https://learn.microsoft.com/en-us/dotnet/api/system.io.file.encrypt?view=net-5.0
And for basic guidance on working with encryption and files in C#, I'd suggest this Microsoft example walkthrough:
https://learn.microsoft.com/en-us/dotnet/standard/security/walkthrough-creating-a-cryptographic-application
may be this could be helpful
// Specifing a file name
var path = #"file.txt";
// Specifing a new file name
var nPath = #"file2.txt";
// Calling the ReadAllBytes() function
byte[] data = File.ReadAllBytes(path);
// Calling the WriteAllBytes() function
// to write the file contents with the
// specified byte array data
File.WriteAllBytes(nPath, data);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
IN SQL SERVER can create XML Document like following format with every column name come with Datafield FieldName="Batch"
CID,BATCH,EXP_DATE are column names.
enter image description here
Try something like
SELECT 'BATCH' AS [DataField/#fieldName]
,BATCH AS [DataField]
,''
,'EXP_DATE' AS [DataField/#fieldName]
,EXP_Date AS [DataField]
FROM SomeWhere
FOR XML PATH('Memory');
The empty string in the middle is needed to start a new element
And be aware, that the dateformat will be ISO8601 and not 190615 (you should be happy about this!)
If you want to achieve XML document creation from C#, then it can be achieved through ADO.net with Help of DataSet. Method name is DataSet.WriteXml(string Filename).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am writing simple program that will assist me to configure and sort out my files.I want the algorithm to search for matching string or text that the user inputs in the search box like windows search index , Google,or any other search engines.I doesn't have to be complex,just simple.you can show me by example or direct me to the appropriate resource.
https://support.microsoft.com/sv-se/kb/303974
Has some information that will get you going.
Edit: string[] files = Directory.GetFiles("C:\\", "*.dll");
This line will search through all files in c:\ for a file thats ending with .dll
Now you want it to search through all files that starts with something then youd have to run "yourstring*". In your example case, you only remember the starting "tes". Directory.GetFiles("C:\\", "tes*"); This line will search for a file starting with the filename "tes"
You can also use Directory.GetDirectories("C:\\"); to get all directories in c:\ and if you want then, loop through those directories with the same method to find all the subdirectories, then search for your file in all of those directories.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I`m using C# and I need to read something after EOF. Is it possible by using C#? How?
Thanks.
You cant. EOF means end of file, there's nothing actually in the file after that.
You may as well ask how you can get ten gallons of oil from a four-gallon drum. Once it's empty, there's no more to be had.
Since you're talking C# hence Windows (and based on your comment and data located behind the end of file pointer), it's possible that they may be referring to "DOS mode" text files, which are (or used to be, I haven't investigated recently) terminated by the CTRL-Z character.
From the earliest days of the PC revolution, where CP/M used integral numbers of disk blocks to store a file and only stored the number of disk blocks rather than the number of bytes, CTRL-Z was used to indicate end of file if the file wasn't an exact multiple of the disk block size.
If that's the case, it's probably best just to open the file as a binary file, then read up to the first CTRL-Z character (code point 26) - everything beyond that could be considered data beyond EOF if it's truly a text file of that format.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm trying to find a way to force illegal characters into a filename. Specifically ':' and '/'
We receive regular automated updates by email. These emails always contain illegal characters in the subject. We currently manually save off these emails for processing as a text file with the subject as the file name. This process works but is tedious.
I wrote a VBA script for saving the files and am working on a small C# application that processes these files locally before sending them of to our server.
The Outlook script simply replaces the illegal characters with a tag before saving:
sTemp = Replace(sTemp, "/", "{FS}")
sTemp = Replace(sTemp, ":", "{CO}")
I need to either find a method to save the files as-is from in the VBA script or change the tags back to the illegal characters when I'm processing locally.
The majority of the team is running Windows 7 x64, using Outlook 2008/10.
The best solution seems to be simply don't. I'm going to rework how we handle these messages rather than try to force this behavior.