Schema.ini file location - c#

I have created some code that works for me using OLE Jet to load a CSV file. I use the schema file to specify delimiter characters that are not the default comma.
The problem I am having is that the schema.ini file appears to have to be placed in same folder as the source CSV. This is fine for a static location but I want to allow the user to browse to any folder to load a CSV file.
Where else can I place the schema.ini file in a scenario like this. I do not want to modify the registry in case it impacts other applications and from my research Jet does not allow the delimiter to specified in connection string.
Is there any way I can build this into the application?

Related

How to read comma file (.csv) and tab separated file(.txt) by a single Flat File Source SSIS Data Flow Item?

I'm new to SSIS and in one of my project I need to read both comma separated file (.csv) and tab separated file (.txt) by a single Flat File Source. Unfortunately I cannot make .txt file content as comma separated because this is how it is generated by a separate source file providing system neither have an option to modify the file content before supply to SSIS. I'm expecting some help and support of your experience.

Automate the process of exporting data from multiple CSV files in a folder

I have already written a script to export data from a single CSV file into SQL Server. I do have to provide the path for that CSV.
I'm trying to figure out how do I modify the code so that it checks a particular folder for CSV files, and then starts processing them one by one. After processing each file, it moves the original file to a different location. Thanks in advance.
Update:
I have a console application written that parses the CSV, connects to SQL database and inserts values. But like I said I have to give the file path. I'm looking for a way to provide only a folder name and the application should look for any CSV files in that folder, parses each file, exports data to SQL, once done moves that file to a different folder and then starts with the next file.
For migrate data from csv try bulk insert
http://msdn.microsoft.com/ru-ru/library/ms188365.aspx
For example
bulk insert [tableName] from 'c:\test.csv'
With (
FIELDTERMINATOR =',',
FIRSTROW=1
)

Save different data settings with C# (variables) not as plain text easy in a specific filepath and access easy

How do I save my data...
(compressed/encrypted) not human readable in a portable file by
influencing on directory name and file name with using easily
addressable settings by "name" and "value" like in registry/ini
with the possibility to access the same one settings file (machine based)
with any executable
In VB I did that with INI Files, but now I have heard from MS that the Framework offers no function to access INI Files anymore. Since INI Files are also not any longer up-to-date for using them in a new application I wanted something similar. Just to write to a text file line by line is not what I want to do, I will explain why: If I will need a setting named "Label4" I have to read the entire file and search for the line containing it and then I have even to split the result in setting name and setting value (.NET has another syntax split function).
Let's say I have a thousand labels and a hundred textboxes in a form and wanna save its content easily to a file or whatever and read it the same easily back addressing the settings by a name already how would I do that? I am ready to use a DB but don't know how to setup and save information there. Easy would be to access the registry with "name" and "value", but I prefer a portable file.
The data shall be stored compressed or encrypted not in a plain text human readable way (I mean XML / html is not what I search for to store the data else I could research again how to use INI files with C# which might be possible I guess). I stumbled upon "application settings" but this doesn't save my data compressed nor can I simply influence on path and filename of the settings file. With each new EXE all the stored settings are lost again for those new EXE if I have used "application settings". I need not "user/application based" settings but "machine based", I hope you understand what I wanna say. Any App on my comp shall be able to get to my settings file
and I shall be able to choose the place/filename where to save the settings.
You should write to any xml file and get your desired results.
(compressed/encrypted) not human readable in a portable file
You can both encrypt/compress a normal file
influencing on directory name and file name with using easily
Can't understand what you mean
addressable settings by "name" and "value" like in registry/ini
xml gives you flexibility you need
with the possibility to access the same one settings file (machine based)
You can keep it machine based.
with any executable
What does it mean?

Difference between a .csv and a .txt file

What is the difference between these two file format.
i found this from Here
.txt File:
This is a plain text file which can be opened using a notepad present on all desktop PCs running MS Windows any version. You can store any type of text in this file. There is no limitation of what so ever text format. Due to ease of use for end users many daily data summery providers use .txt files. These files contain data which is properly comma seperated.
.csv File: abreviation of "comma seperated values"
This is a special file extension commonly used by MS Excel. Basically this is also a plain text file but with a limitation of comma seperated values. Normally when you double click this type of file it will open in MS Excel. If you do not have MS Excel installed on your computer or you find Notepad easy to use then you also can open this file in a notepad by right clicking the file and from the menu select "Open With" and then choose notepad.
My Question :
what does means comma seperated value?
if i'm going to create .csv file using c#, does i need to write file using StreamWriter and does it need to only change the the extention to .csv?
if so do i need to change the writing string with commas?
thanx....
what does means comma seperated value?
Values separated by Comma, for example.
Name,Id,3,Address
if i'm going to create .csv file using c#, does i need to write file
using StreamWriter and does it need to only change the the extention
to .csv?
Changing extension of the file will help you in opening it in MS Excel, other than that it can be anything and you can still open it through your code (StreamReader)
if so do i need to change the writing string with commas?
Yes, separate your values with Comma, or you can use any other delimiter you like. It can be semicolon ; as well since , in some languages/cultures is used for decimal separator.
CSV is structured like this:
"value","value1,"value2"
A text file can be anything from delimited, to free form , fixed width, jagged right, etc...
CSV files can be a pain in the ass if you have commas in your data, and don't properly qualify the values.
I typically create tab delimited or pipe delimited files.
From the perspective of programming, file extensions do not make a difference. In fact you may write comma seperated values inside a txt file.
Comma seperated values indicates the values are just seperated with commas; this is helpful if you want to store some data and share it accross multiple systems (on the otherhand XML is a better option).
Assume you need to store name, age and location;
TilT,25,Germany
is a comma seperated data.
In the scope of c#, you need to add commas between your values and you may save it as a CSV file or a TXT file; it makes no difference.

Include editable file in c# .exe

I would like to embed a .txt file into my C# project storing a list values for the user. These values should be configurable and therefore the .txt will have to be edited during runtime. I have found out that Embedded Resources cannot be modified. Is there any other way to do that?
Thank you.
Store the text file as an embedded resource. The first time your program is run, copy the embedded resource to a file on disk, and use it for the configuration. Your users can edit the disk file.
The embedded resource version serves as a default configuration.
You can use your app.config or web.config configuration files.
Normall if you will use large amout of data using a database is recommended. I assume you really need just a .txt document. In your assembly write a procedure that will create that text file if its not present. To be more specific lets say your program is mainProgram.exe. In onload event of mainprogram.exe write a procedure checkTxtFile(). This procedure first will check if there is a txt file in the directory.If the file is not presend it will create it with the desired values.
You can create a XML file using Filestream and using it during runtime or
make your own protocol format and store the data in the file so that no one can change it.
Over to that you can also encrypt and decrypt the file on the fly.
Lists of modifyable, persistable values are best stored in a database. There are many lightweight options to choose from; in this case I think a SqlLite database would suit your purposes best.

Categories

Resources