|
the simplest solution probably goes like so:
- keep key,value pairs in the file, one per line, all keys unique, key and value separated by some symbol (= seems the obvious choice);
- read all lines with File.ReadAllLines
- inside a foreach loop, split the line using string.Split('=',2), use the first part as a key, the second as a value, and stuff that into a Dictionary
Done. Less than 10 lines of code.
|
|
|
|
|
Possibly dumb question but how do I use the key you stated? I know its an identifier for the value string but do i just use my code to search for it? Like <code> if (s.IndexOf("fn:") != -1) </code> ? or what?
|
|
|
|
|
You create the dictionary like so (omitting error handling):
Dictionary<string, string> dict=new Dictionary<string, string>();
foreach(string s in File.ReadAllLines(path)) {
string parts[]=string.Split('=', 2);
dict.Remove(parts[0]);
dict.Add(parts[0], parts[1]);
}
You look up a key's value by using the key as an index to your dictionary, like so:
string name=dict["Name"];
You enumerate all key-values (maybe not in original order!) like so:
foreach (KeyValuePair<string, string> kvp in dict) {
log(kvp.Key+"="+kvp.Value);
}
You could also prepopulate the dictionary with default values for some keys:
dict.Add("Name", "Jef");
dict.Add("Occupation", "Software Engineer");
|
|
|
|
|
|
Is the file physically saved anywhere in order for me to acess it later? if so, how do I bring up a dictionary object from a file?
|
|
|
|
|
Hi,
you could save settings to disk by creating a loop, similar to the foreach I have shown; and later reload just like you load the first time.
PS: replying to yourself, I did not get a notification and saw your message only by accident.
|
|
|
|
|
I am testing out using Exchange Webservices to post tasks to the current user in a corporate intranet.
The code below works when I run it through Visual Studio 2008 debug mode, but when I publish it to the intranet site, it bails with the following error:
Microsoft.Exchange.WebServices.Data.ServiceResponseException:
When making a request as an account that does not have a mailbox, you must specify the mailbox primary SMTP address for any distinguished folder Ids.
I have disabled anonymous access to the website and have it set security to Integrated Windows Authentication.
As you can see below, I am passing the default credentials to the web service.
What am I missing here?
Any help will be appreciated.
public class ExchangeTask
{
ExchangeService myService = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
public ExchangeTask()
{
ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
myService.UseDefaultCredentials = true;
myService.AutodiscoverUrl(EmailAddressToFind);
ServiceURL = myService.Url.ToString();
}
public void SendTask()
{
Task myTask = new Task(myService);
myTask.Body = "This is a reminder task that has automatically been set by ExchangeWebservices";
myTask.DueDate = DateTime.Now;
myTask.ReminderDueBy = DateTime.Now;
myTask.StartDate = DateTime.Now;
myTask.Subject = "Event Reminder Task";
myTask.Save();
}
|
|
|
|
|
Just in case anyone ever looks at this question again,
The solution was to put <identity impersonate="true" /> in the web.config file under <system.web>
|
|
|
|
|
I'm having same problem.
You can try adding: <identity impersonate="true"> in the web config.
If I hardcode a user, password, and domain it works fine, but trying to get cached credentials seems hopeless.
|
|
|
|
|
I have the following xml:
<Resume>
<Details>
</Details>
<Contacts>
</Contacts>
</Resume>
how can I add childs to the Contacts using C# but with referring to the <Contacts> by name not by ID?
I want to add:
<Contacts>
<Contact ID="xxxxxxxx">
<Category>my category</Category>
<Number>my contact number</Number>
</Contact>
</Contacts>
|
|
|
|
|
|
You can use c# DOM to access the XML or DHMTL.
Try this:
http://progzoo.net/wiki/C%23:Navigating_over_DOM_Tutorial
modified 27-May-14 4:40am.
|
|
|
|
|
As I already said, look to XPath.
If you load your XML into an XmlDocument, you can get the desired contact by doing:
xmlDoc.SelectSingleNode("/Contacts/Contact[@ID='xxxxxxxxx']");
Then, you have a reference to the node into which you can add subnodes.
|
|
|
|
|
Hi,
I am fairly new to programming and I am making member registration apllication.
The main form contains a DataGridView with all the checked in members. The DataGridView connects to a
stored procedure. This main form is also the start-up form.
In the search results form I can check in / out a member. This done by clicking a button that calls a stored procedure.
Now for my question:
After I click the checkin / out button I want to update the DataGridView in the main form.
I don't seem to be able to make this work.
Below is the code that I use.
The following method is placed on the main form. This is the method I want to call from the other form.
public void FillDataGrid()
{
this.aLL_CHECKED_IN_MEMBERTableAdapter.Fill(this.on_target_v1DataSet.ALL_CHECKED_IN_MEMBER);
}
I want to call this method through the following code, this code is located on a different form:
public void btnCheckIn_Click(object sender, EventArgs e)
{
Procedures.CallStoredProcedure.CHECK_IN_MEMBER(this.lblNumber.Text);
CheckInOut(this.lblNumber.Text);
frmMain cls = new frmMain();
cls.FillDataGrid();
}
Does anyboady have any ideas how I can tackle this?
Regards,
Paul Stol
|
|
|
|
|
|
Using events as mentioned above. See this tip[^] and this article[^].Dave
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Hi to all! I'm having the following problem and I would like some help on trying to solve it.
I'm trying to correct a problem I detected in a code from a project I'm working on (the code is not mine and since the person who made it is no longer in the team I have no way of knowing why this was made this way).
I've spoted a cast from double to long that doesn't seem to work out very well. The idea is to convert the double value to a long so that it can be compared between two other longs (max and minimum values in a specific scale). The code is something like this:
minValue = 56;
maxValue = 70;
value = 55.99.
if ((long) value >= minValue && (long) value <= maxValue)
{
....
}
The problem is that the cast makes value to be 55, instead of 56. Checking other alternatives, I saw Convert.ToInt64, that, for this example works. However, it does not work the way I wanted if the value is say, 70.5, in this case I'm stuck with 70, when I would like to have 71, like I saw on MSDN ("If value is halfway between two whole numbers, the even number is returned; that is, 4.5 is converted to 4, and 5.5 is converted to 6.").
Can anybody point me to the correct way of converting a double to long, without this problem with rounding the even numbers?
Thanks in advance!
|
|
|
|
|
I know it doesn't answer the question exactly as it was asked but...have you thought of reversing the conversion for comparison?
if(value >= (double)minValue && value <= (double)maxValue) "I need build Skynet. Plz send code"
|
|
|
|
|
That won't work if he does math on either of the values..45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
You may have to round the number using one of the three rounding methods:
Math.Round which rounds to the nearest whole number
Math.Ceiling which rounds to the next highest whole number
Math.Floor which rounds to the next lowest whole number
Your comparison should be something like this:
if (Math.Round(value) >= minValue && Math.Round(value) <= maxValue)
{
} .45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
That doesn't make much sense to me. I'll have to guess what you intent. You not showing the declarations does not help.
If all of those variables are doubles, then compare doubles, unless your conditional block is really going to do something with (long)value . If so, it deserves to be represented by a local value and an all-long comparison is in order, that would yield:
long minValue = 56;
long maxValue = 70;
double value = 55.99.
...
long longValue=(long)value;
if (longValue >= minValue && longValue <= maxValue) {
do_something_with(longValue);
}
|
|
|
|
|
Luc Pattyn wrote: That doesn't make much sense to me.
Just pray it's not the code that's calculating your credit card bill. txtspeak is the realm of 9 year old children, not developers. Christian Graus
|
|
|
|
|
...that'd be an easy calculation. 0 "I need build Skynet. Plz send code"
|
|
|
|
|
I'll make sure my expenses stay outside the [55, 71] range. And I'll double check.
|
|
|
|
|
Why would you want to round up from 55.99 to 56? 55.99 is not greater than or equal to 56. I'd say rounding down is the correct behavior there. However, for maxValue, then you might want to use Math.Ceiling to round up (well, since Math.Ceiling returns a double, you'd round up then cast to a long if you really want a long for some reason). The alternative would be to not round at all and the comparison will work fine (the longs will be promoted to doubles when you do the comparison.
My guess is somebody did the rounding because they didn't think it through very well. But there may be some perfectly valid reason that would be easier to determine if we know what code was replaced by "....".
Side note: this could possibly have something to do with setting pixel values. That is a common place for integers to be required for comparisons and such when the underlying values are really floating point numbers (e.g., doubles).
Fenryl wrote: value = 55.99.
FYI, I assume that "." is supposed to be ";".
|
|
|
|