|
I did not edit the app.config file at all. What do I need to put in the app.config file?
|
|
|
|
|
Yeah, that's what drives the whole thing . Did you create the Settings.settings file? You should create your settings through the Visual Studio settings editor and that'll populate the app.config for you.
|
|
|
|
|
I would have done that from the beginning but my type is not supported there.
|
|
|
|
|
You can do custom types there, but its a little tricky . Once you get your code all compiling, in the type you select Browse and in the edit box, you type in the fully qualified name of your type.
Hmm... I just tried this in VS2012 and I guess they don't write to the app.config for custom types anymore. They did in 2010.
Did you check your AssemblyInfo.cs file? If you don't have a company name specified, it won't work. That I did just verify.
In addition, what does your Account class look like?
Do you have public PROPERTIES and not public variables? Do you have a public parameterless constructor?
I didn't need the constructor in my test app that i just tried... just trying to trouble shoot all the gotchas .
|
|
|
|
|
I didn't have a company but I added it and it didn't help. I will just put the code for the class and the nested class. Also as I noted before I never touched the app.config file so if I do need to make changes to that then I would need to know how to do that.
Here is the Accounts class
[Serializable]
public class Accounts
{
public Accounts()
{
List = new List<Account>();
}
public List<Account> List { get; set; }
public decimal TotalBalance()
{
decimal balance = 0;
foreach (Account a in List)
{
balance += a.Balance;
}
return balance;
}
public decimal TotalEquity()
{
decimal equity = 0;
foreach (Account a in List)
{
equity += a.Equity;
}
return equity;
}
}
And here is the Account class
[Serializable]
public class Account
{
public Account(string path)
{
Path = path;
Initialize();
}
private bool Initialize()
{
using (FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(fs))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
Broker = values[0];
Name = values[1];
AccountNumber = values[2];
Balance = decimal.Parse(values[3]);
Equity = decimal.Parse(values[4]);
break;
}
}
}
return true;
}
public bool Update()
{
using (FileStream fs = new FileStream(Path, FileMode.Open, FileAccess.Read))
{
using (StreamReader reader = new StreamReader(fs))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
Balance = decimal.Parse(values[3]);
Equity = decimal.Parse(values[4]);
break;
}
}
}
return true;
}
private string Path;
public string Broker { get; set; }
public string Name { get; set; }
public string AccountNumber { get; set; }
public decimal Balance { get; set; }
public decimal Equity { get; set; }
}
|
|
|
|
|
A class will not xml serialize unless it has a public parameterless constructor. For successful deserialization it must be possible to completely set the object's state by assigning values to it's public properties.
In effect the deserializer is doing something like this:
Account acc = new Account();
acc.Broker = savedBroker;
acc.Name = savedName;
.... etc.
Without the necessary public parameterless constructor the serialization will silently fail (really helpful Microsoft!). You can add the constructor but then it looks like an Account cannot be restored fully as the object is strongly coupled to a specific file via the Update method and the Path has not been serialized. Think about the design carefully before adding a public Path property as the information stored in the file and in the serialized settings may be different.
Alan.
|
|
|
|
|
Is this only for certain kinds of serialization because I just in the past few minutes successfully manually persisted the objects using the following code. It works perfectly except that it uses a file that the user can screw with which I wanted to avoid. I.E. They could move the program without the file.
for loading
if (File.Exists(settingsFileName))
{
Stream TestFileStream = File.OpenRead(settingsFileName);
BinaryFormatter deserializer = new BinaryFormatter();
accounts = (Accounts)deserializer.Deserialize(TestFileStream);
TestFileStream.Close();
foreach (Account a in accounts.List)
{
ListViewItem item = new ListViewItem(new string[] { a.Broker, a.Name, a.AccountNumber, a.Balance.ToString(), a.Equity.ToString() });
listView1.Items.Add(item);
}
}
for saving
Stream TestFileStream = File.Create(settingsFileName);
BinaryFormatter serializer = new BinaryFormatter();
serializer.Serialize(TestFileStream, accounts);
TestFileStream.Close();
|
|
|
|
|
Yes, binary serialisation works differently and does not have the constructor/public property constraints of xml. There is information on MSDN but it's quite heavy going and the implications of what they're saying may not become apparent until you've made a few mistakes of your own.
Serialization[^]
Good luck, Alan.
|
|
|
|
|
ok so after getting frustrated I decided to run a test. My thinking was that maybe it can't save it. It would seem this is correct but I don't know why. I tried to save a string using the same method and it worked without editing the app.config file. So then I would try just to save one instance of the nested class Account and it did not work either so who knows.
|
|
|
|
|
hi to all
i have a very complex problem in crystal report can every one help me for this problem?
thanks for any idea
my problem:
i have a report when my store procedure return 30 row ,this rows
show in two page ,row 28 will be disappeared and remove from the report.
i re size my report header and footer ,but my problem is already exist
|
|
|
|
|
Post it in a different forum with report sections screen shot to get the answer. People will look for C# questions here.
modified 11-Apr-13 6:00am.
|
|
|
|
|
|
Hi I been searching for a source code of flow free puzzle game, does anybody tell where can find it?
in c#
|
|
|
|
|
I found lots of them here[^]
|
|
|
|
|
I wrote an application which "pops" the local mail agent, fills out the recipients,cc,bcc,subject, and body fields..
question is, given a file path,how do i automate the process of attaching a file to that email and sending it?
Scoured the web without finding a solution,
So help will be greatly appreciated
annex
|
|
|
|
|
What do you mean by "pops"??
How are you accomplishing what you already have?? If it's launching a "mailto:" link, attachments are not supported.
|
|
|
|
|
You need to read the SMTP spec for multipart messages and MIME encoding.
|
|
|
|
|
If I were you I'd use the .NET API to achieve your goal.
See here: MailMessage Class[^]. It even sports an example with an Attachment[^].
Regards,
— Manfred
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
You don't mention if but if you are working with Outlook as the local mail agent, there are a number of pain is the butt things you have to look out for... including the security authorization pop-up when you try to send mail via Outlook from another application and the restrictions around attachment types and the automatic stripping that can occur.
If you have to deal with Outlook, there is a library called the "Outlook Redemption" library which makes it a breeze. I've used it before and it is by far the best way to deal with Outlook as the local mail agent. Especially if you have to send via Exchange because you don't have to setup a risky SMTP relay on the exchange server. The website is here: http://www.dimastr.com/redemption/home.htm[^] And best of all, you can send e-mail as the current user without their intervention... no need to 'pop' the message if you don't want to.
|
|
|
|
|
i want record guitar sound from microhone
and in my program detect note of it
is it possible ?
|
|
|
|
|
|
Thanks for the link to an interesting article. 5+
Cheers!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Manfred R. Bihy wrote: Thanks
You're welcome!
|
|
|
|
|
in my example it's show that I put only one marker but lets say I add much more markers and I only want to remove marker in my array in index 0.
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked == true)
{
GMap1.addGMarker(markers1[0]);
}
else
{
}
}
|
|
|
|
|
..and who told you what to write in the first "if"?
The "addGMarker" method returns an object, and according to the documentation one could call the "remove" method on that object. Says here on the page it's deprecated. What version of GMaps are you using?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|