i specified the connection string and my file path in app.config like this
<configuration>
<connectionstrings>
<add name="nConnectionString">
connectionString ="Data Source=CSZ-PCS43132\SQLEXPRESS;Initial Catalog=test;Integrated Security=True"
providerName="System.Data.SqlClient"/>
<appsettings>
<add key="empdetails" value="~/C:/Documents and Settings/aj99823/Desktop/project/Employee Details.txt">
and in the front end i called them as
public void employeedetails()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["nConnectionString"].ConnectionString);
// using (SqlConnection connection = new SqlConnection(str))
{
try
{
conn.Open();
}
catch (System.Data.SqlClient.SqlException ex)
{
return;
}
string selectCommandText = "SELECT distinct userid,fullname,lastname,firstname,localjobtitle,employmentstatusid,dateofjoining,dateofexit,siteid,email,topfunctionid,active,exitingthecompany,lmsroleid,locallanguagejobtitle FROM tblUserProfile up,tblreportingto tr,tblCountry where temo is null";
using (SqlDataAdapter adpSQL = new SqlDataAdapter(selectCommandText, conn))
{
using (DataTable table = new DataTable("tblUserProfile"))
{
adpSQL.Fill(table);
StringBuilder commaDelimitedText = new StringBuilder();
//commaDelimitedText.Append("EMP_Number|Name|Lastname|Firstname|Middleinitial|NameSuffix|Positiontitle|EMPcode|EMPstatus|Manager number|Approvernumber|Startdate|Enddate|Lastreviewdate|Address1|Address2|City|State|Zipcode|Country|Email|Phone1|Phone2|Fax|URL|Note|DomainCode|Organizationcode|Jobcode|Active|Enabled|Username|NTlogin|Role|Timezone|Currency|Language|Text1|Text2|Text3|Text4|Memo1|Date1|Date2|Indicator1|Money1|Integer1|Float1|JobJoiningdate|Organizationjoiningdate");
foreach (DataRow row in table.Rows)
{
string value = string.Format("{0}|{1}|{2}|||{3}||{4}|{5}||||||{6}||{7}|{8}|{9}||||||||{10}|{11}|{12}|{13}|", row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14]);
commaDelimitedText.AppendLine(value);
}
File.AppendAllText(ConfigurationManager.AppSettings["empdetails"], commaDelimitedText.ToString());
}
}
}
}
But it is throwing error saying failed to initialize the connection.
if i put the just after the my connection string will get initialized successfuly but it will throw error where i specified the file path.....that is the following line...
File.AppendAllText(ConfigurationManager.AppSettings["empdetails"], commaDelimitedText.ToString());
can anyone please help me?????????????