.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

How to specialize the path of configuration file which the application about to read?

Posted By:      Posted Date: October 16, 2010    Points: 0   Category :.NET Framework

Simplily, i have a solution which can be normally run, but after i renamed the app.config to otherName.config, the app would not file the configuration file at its runtime. so how to specialize the path(include the file name such as otherName.config).



i recently build a WCF solution, in Server project, i manipulate data by using ADO .NET Entity Framework. both WCF Host project and EF project needed their configuration files and the default name of these configuration files is app.config.

When we code, there is no need to manipulate the XML formatted app.config file, we just use following codes, ant the .NET application can automatically retrieve elements from app.config:


 // WCF Project
 using (var host=new ServiceHost(typeof(Server.Settings.Configration))) {
 Console.WriteLine("WCF has been started, press any key to end..");
// EF Project

View Complete Post

More Related Resource Links

Read Excel file from Web Application (C#)



I have a web app where user uploads a file.

File is saved in server locally and I want to read some data from it.

Currently my development  server has office 2003.

So do I need office 2007 in order to be able to  read an excel from office 2007 ?

What are other requirements  ?

I tried a test, using

Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook wrkBook; // = new Microsoft.Office.Interop.Excel.Workbook();

wrkBook = excelApp.Workbooks.Open(@"C:\www\excel_files\b.xls", ....);

But When trying to open the file I get the error:

Exception from HRESULT: 0x800A03EC

So I'm wondering what I'm missing.


using application configuration file in AppData special folder

Hi! So I understand it is a best practice to save the application configuration files under the AppData folder, rather than in Program Files, since UAC will restrict write acces to the Program Files folder, which is fine. Now, saving the configuration file to another location is no problem, using the SaveAs method. However, when I load the application, I expect some settings to be read. From what I know, this is done either using direct calls to the ConfigurationManager class, either initializing a Configuration object. For the first case, a example is this: if (ConfigurationManager.AppSettings["Title"] != null) { this.Title = ConfigurationManager.AppSettings["Title"]; titleTextBox.Text = ConfigurationManager.AppSettings["Title"]; } For the second case, I would use it like this: Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); string setting = config.AppSettings.Settings["Title"].Value.ToString(); So, if the application runs in the Program Files folder, an exception is thrown when I save the file. However, if I save the file using SaveAs and save it to AppData folder, obviously, when loading, the settings are not loaded from the AppData folder, but from the configuration file existing in the Program Files folder. One way to solve

JS script file path screwed up after deploying MVC application

Hi,  I am relatively new to MVC, after deploying my MVC application as per Haack http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx i seem to have got a new problem. My Jquery doesnt seem to get recognized. I get "object doesnt support this property or method " at this line "jQuery(document).ready(function() {" i have tried all sort of things including changing the js script file path to relative and absolute, setting base tag etc. Kindly advice if the above method of deploying is right and if that is what is causing the issue and if there is some other way to handle the .mvc requests.   Thanks and Regards, Muzammil Ahmed

Manual change to "applicationSettings" in app.config file are not read by the application.



Okay...This Application Settings stuff is driving me nuts.  Something conseptually so simple should not be this hard to get working.

Here is my

I have a .NET 4 application in which I generated a web reference from a web service wsdl.

I see that it creates an endpoint property in the app.config file which corresponds to a settings class that is autogenerated.    I compile my release code and copy the executable and config file to a local drive.

By default, the url points to the endpoint that was added by the designer.

Now, I want to change my application configuration to point to the production version the the webservice.

To do this I thought all I had to do was change the value in the app.config file.  However, the application never reads from the config, it's always taking the default setting compiled into the settings class.  I'm at a loss as to why this is happening. 

I have search through this forum and there are so many different posts on application settings but all I want to do is change the config file manually without having to recompile.   I'm not doing any runtime settings modifications. 

What if down the line we change the alias to the web service hosting the service.  I can't imagine Microsoft really expects us to have to rec

Cannot deploy application with SQLce datbase.sdf file. says file path is wrong?!


I am trying to deploy a simple windows desktop app using a SQLce database.sdf file. I have followed the steps in this walkthrough about 10 times and I still am having problems. http://msdn.microsoft.com/en-us/library/bb546200.aspx

In my app config file my connection string is this:


 <add name="VendorTracker_2._0.Properties.Settings.Database1ConnectionString"

          connectionString="Data Source=C:\Users\Eamon\Documents\Visual Studio 2008\Projects\VendorTracker 2.0\VendorTracker 2.0\Database1.sdf"

          providerName="Microsoft.SqlServerCe.Client.3.5" />


According to the walkthrough, the windows installer should recognize that i am using a sqlce .sdf file and create a new connection string: 


<add name="VendorTracker_2._0.Properties.Settings.Database1ConnectionString1"

            connectionString="Data Source=|DataDirectory|\Database1.sdf"

            providerName="Microsoft.SqlServerCe.Client.3.5" />


It does add this connection string to the app config file. Now I

How to Read Unix File System From C# APplication ?


Hello All , 

i have task to make an Application to Read UNIX File System , and i'm C# Programmer and i don't know anything in UNIX or have any relevant Knowledge to this issue , can you help me  or give me anything as start point ?


thanks in advance

Kareem Naguib

New off line application working with sdf file. Need advice


Hey Folks

I am working on a project currently where I need to get data out of a 3rd party vendor's software that uses a .sdf file I looked this up and its a SQL CE file. I was hoping to just link to with with access but thats apparently not going to happen. I need to link to the database extract data from it to a csv file for later use. I also and most important I need to get the data from it and create a report that can be printed while on a customers site that my or may not have web access so I need for this program to be on and off line. I had my webapplication that I have been working on open and was able to bring up the sdf file under the server exploere however I can't seem to get anything out of it when I try to do grid views or detail views errors out.

Can I use one of Visual Studio projects to create this sort of applicaiton if so what would be the best approach. I would love to get an access odbc driver since office is allready installed on the employee's laptop's



I am not able to read xml file with XDocument if its Descendants has Attribute xmlns="http://abc.co


I am not able to read xml file with XDocument if its Descendants has  Attribute like:-

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
  <row ID="1" xmlns="http://www.opentravela.org/OTA/2003/05">
    <var country_name="Caribbean and Rest of the world" city_name="Kingston" flight_category="Economy Class" via="Atlanta" flight_departure="London Heathrow" airline_logo="Delta" adult_fare="Delta" child_fare="660" infant_fare="561" date1="132" date2="2010-08-15" />


I don't know what to do ?

Looking for some help..

An example of packaging web application containing database upgrade SQL file

A few months ago, we have a blog talking about extending the web publishing pipeline to package database project deployed SQL file.  In this blog, I'll show step by step example of packaging web application with SQL Server database upgrade SQL file using Visual Studio 2010.  This way, we can generate a web package with incremental SQL script to certain database version.  The scenario may help distributions of a web upgrade package which needs to be installed on many different locations, each with their own SQL server database.   1. Create a Web Application Project 2. Add a new "SQL Server 2008 Database Project" to the solution 3. Prepare a development database, such as my test1 database as the following: 4. Right click our...(read more)

File Attachments from info-path forms to Sharepoint document library


Hi Experts,

How to upload file attachements from info-path forms to Sharepoint document library?

I need to add attachement from local-PC/Any User to Sharepoint Document Library.


Any help please?? Appreciated




Moved from WinXP to Win7 - don't see choice to open file in read only or edit mode


I just recently moved from Win XP Pro SP3 to Win 7 32-bit Pro. I am logging into domain X normally. Our Sharepoint 2007 server authenticates only on domain Y. So I start Internet Explorer with "run as different user" and provide my domain Y credentials. All fine. 

In win XP, after I did this, when I click on an Excel file on Sharepoint, I would get a dialog asking if I wanted to check out and edit or open as read only. 

In win7, I don't get that choice. The file simply opens, and I get a bar at the top which allows me to check out the file if I wanted to. 

How can I restore the functionality I used to have, with the dialog for checking out the file before opening it?

How do I find the file path from a namespace.class name?


I'm programatically looking ito a .aspx file and getting the file class name declared in its CodeBehind. For example, when analyzing myFile.aspx I read in its Page Directive and found its CodeBehind equals "myApplication\myPage.aspx.vb". Then I use the code below:


Dim Assm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("myApplication\bin\myApplication.dll")
Dim ClassType As Type = Assm.GetType("myApplication\myPage.aspx.vb")
' myBaseType = "myApplication.Forms.BasePage"
Dim myBaseType As System.Type = ClassType.BaseType


Now I want to read the BaseFile (class = myApplication.Forms.BasePage). However, to read in this file, I need I need to get its full path instead of its namespace.class hiearchy. In this case, the BasePage is wrapped in a different namespace declaration thus I cannot just change the '.' to '\' in order to get the path.

How can I get the path of BasePage so I can read it? Thank you - Frank

Managing Custom Configuration Options for a SharePoint Application

Learn how to store configuration data in various ways, including inside the web.config file on front-end Web servers, by using the property bag on various Windows SharePoint Services objects, storing configuration data within SharePoint lists, and by using the hierarchical object storage.

how to consume the dll file which is registered in GAC, into my asp.net web application



i have created a strong name key to my dll file...and then i have added it to GAC.

In general, to add a .dll file in the solution explorer, right click -> add reference...

How should I refer the dll file registered in  GAC



Unable to read beyond the end of the stream in asp.net 2.0/C# web application


Hi All,

Thank you for advance.

I got the forllowing error in my asp.net 2.0/c# web application,

Message: Unable to read beyond the end of the stream.

Source: mscorlib

TargetSite: Void EndOfFile()

StackTrace:    at System.IO.__Error.EndOfFile()
   at System.IO.BinaryReader.ReadByte()
   at System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader)
   at System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader)
   at System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader)
   at System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader)
   at System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader)
   at System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader)
   at System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader)
   at System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader)
   at System.Web.UI.ObjectStateFormatter.DeserializeValue(SerializerBinaryReader reader)

Designer crashes sometimes because application path becomes C:\Windows\system32

Sometimes VS crashes as it seems to execute the WPF designer in its directories or C:\Windows\system32. Sometimes it works fine as we can preview saved settings in the Designer. I have set application path as follows : ConfigFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mixer.ser");<br/> When VS crashes I accept to debug it, the exception is : {"Access to the path 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\mixer.ser' is denied."}    System.Exception {System.UnauthorizedAccessException} ... or c:\windows\system32 Any ideas on how to fix this ?   Thank you !
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend