Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am Creating Windows application(C#) in that I want to get Connection String from text file ......
Please help me regarding same...
Posted
Updated 29-Jan-18 21:35pm
Comments
Mehdi Gholam 8-Sep-12 2:11am    
Which part can't you do?
Deepak_Sharma_ 8-Sep-12 3:00am    
Why are you storing connection string in a text file instead of app.config. Which is more secure and manageable.

You should use FileStream Class[^] and StreamReader Class[^] to read the data from a text file.

Refer the articles below for example:
How to use C# FileStream Class[^]
FileStream Open File [C#][^]
C# StreamReader[^]
How to: Read Text from a File[^]


--Amit
 
Share this answer
 
This code can help you:

C#
string connStr = System.IO.File.ReadAllText("filename.txt"); 


Change filename.txt info the name of your file.
Then, connStr contains the contents of the file.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900