|
I am encountering a problem while reading config files. The scenario is like this, I have two programs. Program A reads its configuration from a config file and program B is only used to modify the contents of the config file which A reads. The name of the config file is email.config. It is in the same directory in which program A & B resides.
The problem is that I get path of a file for attachment using open file dialog in program B. If the path points to a file in the same directory, program B works perfect while saving the data back to the config file! But if it points to a file outside the directory it throws an exception of type System.NullReferenceException.
I have placed comments in the code where the exception occurs.
Here is the code
static readonly string configFileName = "email.config";
private void saveBtn_Click(object sender, EventArgs e)
{
try
{
string serverAddr = serverAddressTxtBox.Text;
string port = portTxtBox.Text;
bool ssl = sslRadioYes.Checked == true ? true : false;
string senderAddr = senderTxtBox.Text;
string password = passwordTxtBox.Text.Length != 0 ? Encrypt(passwordTxtBox.Text) : "";
string subject = subjectTxtBox.Text;
string attachment = attachTxtBox.Text;
string messageBody = msgBodyTxtBox.Text;
var configMap = new ExeConfigurationFileMap { ExeConfigFilename = configFileName };
Configuration externalConfig = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
externalConfig.AppSettings.Settings["ServerAddress"].Value = serverAddr;
externalConfig.AppSettings.Settings["Port"].Value = port;
externalConfig.AppSettings.Settings["SSL"].Value = ssl.ToString();
externalConfig.AppSettings.Settings["Sender"].Value = senderAddr;
externalConfig.AppSettings.Settings["SenderPassword"].Value = password;
externalConfig.AppSettings.Settings["Subject"].Value = subject;
externalConfig.AppSettings.Settings["AttachmentPath"].Value = attachment;
externalConfig.AppSettings.Settings["Body"].Value = messageBody;
externalConfig.Save(ConfigurationSaveMode.Full);
Application.Exit();
}
catch (System.Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
Application.Exit();
}
}
|
|
|
|
|
What object is null? Is it externalConfig, externalConfig.AppSettings or configMap? What format is your external path in? Have you escaped the backslashes correctly in your external path?
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
The externalConfig.AppSettings.Settings collection is null, it doesn't have any keys loaded.
|
|
|
|
|
Well, I configured it out myself after debugging for almost 5 hours, Damn!
The problem was when I used OpenFileDialog to get the file path, it changed the current directory to the one which is selected in the dialog, so the program couldn't find the config file. All I did was to set the RestoreDirectory property of OpenFileDialog to true and *poof* it worked
|
|
|
|
|
HI
I have three tables
1. Categorys (ID, Name)
2. Definitions (ID, Name, CategoryID)
3. Versions( ID, Name, DefinitionID)
I have generated three objects using EDM
1 Cagegorys
Navigation (Definition)
2. Definitions
Navigation (Category, Version)
3. Versions
Navigation (Definition)
I have following problems
1. I want to update the category of a version
2. I want to get all version against a specific Category
I need Code in C#.Net or VB.Net
|
|
|
|
|
I need a Ferrari. It can be red or yellow.
|
|
|
|
|
Unlucky, I have a blue one I'm trying to give away
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: Unlucky, I have a blue one I'm trying to give away
I'm not so fussy. I'll take it.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Sorry... just my dreams speaking out loud again
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Member 3374813 wrote: I need Code in C#.Net or VB.Net
Two things:
1. There isn't such a thing as C#.NET - it's C# and it targets the .NET framework.
2. I don't work for you, so why should I write code for you?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Please do not joke. I need it urgent
|
|
|
|
|
Member 3374813 wrote: Please do not joke. I need it urgent
He isn't joking. If you want something you need to be polite. The word "urgent" is a sure way not to get help because it is rude and this is a voluntary forum. No one gets paid to post here. If you need help urgently then you can get paid for support that will answer your questions in a timely manner set out by the terms of service.
Man who stand on hill with mouth open wait long time for roast duck to drop in
|
|
|
|
|
Member 3374813 wrote: Please do not joke. I need it urgent
This site is not good for urgent queries. I'll recommend you rentacoder[^] for that!
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
It's no joke. I don't work for you, and presumably you won't be paying me, so why should I write your code for you? If your need is that great, consider hiring a codemonkey off rentacoder, and as far as the urgency goes, this doesn't even make it into my top 500 things to care about today list. It's only urgent to you - not me.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
After an extensive research period I would recommend using SQL queries somewhere
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Yes I need esql Query. I am new to Entity framework. I need Entity SQL or LINQ Sql query for my problem

|
|
|
|
|
Member 3374813 wrote: I have three tables
So do I...
1. Coffee Table
2. Dinner Table
3. Bed-side Table
Member 3374813 wrote: I have following problems
My problem is singular...
1. You
Your problem is...
1. You are trying to do something you are incapable of doing (programming that is)
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: 3. Bed-side Table
Do you mean night table
|
|
|
|
|
I mean a table you put at the side of your bed - Call it what you will
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: I mean a table you put at the side of your bed - Call it what you will
Well why didn't you say so.
A Call it what you will Table.
Using the correct names for Controls/Classes, can make the difference between getting an answer and getting the bird!!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Can anyone give advice on how to do this?
I am using a DeveloperExpress Grid linked to a BindingSource.
I import data into the bindingsource from a flat file then perform various checks to ensure the data is valid. If not, I set a column error for the row - as follows...
if (view.GetRowCellValue(intRow, "intX") == null || Convert.ToDouble(view.GetRowCellValue(intRow, "intX")) == (double)0.00)
{
dr.SetColumnError("intX", String.Format("{0}: Missing value.", view.Columns["intX"].Caption));
}
I have a button on the form to allow the user to filter the grid so that the grid will hide all valid rows to allow them to concentrate on fixing the invalid rows.
Can someone tell me how to apply a filter to the binding source to only show those rows with one or more column errors?
Many Thanks
|
|
|
|
|
Something like:
bindingSource1.Filter = "intX == null || intX == 0.00";
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry, Thanks for the reply.
I realise I can do that - the problem I have is that there is far more to the error checking than the small snippet I posted and it will not be feasible to do it this way. I could put in a dummy column and set the value to 1 within my error checking code on finding an error and filter on the dummy column = 1. However, I was hoping there was some way I could get a collection of the rows containing an error and use that to filter eg = extract all the ids of the rows with one or more errors into an array then convert that into a filter string... ID = id1 or ID = ID2...
|
|
|
|
|
Well in a .NET DataGridView you could iterate over the DataGridRowCollection and do that. I would assume the DevExpress version has the same functionality. Whether that is practical depends on the number of rows involved, from a time point of view.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry - that's the approach I've now gone for...
string strFilterString = "";
sp00134BindingSource.Filter = ""; // Clear any Prior Filter //
foreach (DataRow dr in this.dataSet_AT.sp00134.Rows)
{
if (dr.HasErrors) strFilterString += " or ID = '" + dr["ID"].ToString() + "'" ?? String.Empty;
}
if (strFilterString.Length > 4) strFilterString = strFilterString.Remove(0, 4); // Remove initial " or " clause //
if (strFilterString == String.Empty) return;
try
{
sp00134BindingSource.Filter = strFilterString;
}
catch (Exception Ex)
{ .....
Thanks for the pointer. 
|
|
|
|