|
thanks.. the second one works..
however.. for the first one... is this the correct code?
TextWriter tw = new StreamWriter("Server.MapPath/images/info.txt");
also.. if i write 2 or more image files... it will overwrite the exisiting one... how do i make it so that it will write onto next line in my textfile
modified on Thursday, May 1, 2008 9:52 AM
|
|
|
|
|
Wow.
OK, what have we learned ? When a string is in quotes, it becomes a literal string, NOT code. Try copying the code you use above, and it will work.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
ok thanks...
also.. if i write 2 or more image files... it will overwrite the exisiting one... how do i make it so that it will write onto next line in my textfile
|
|
|
|
|
Hi guys. I need help please. I have two functions in my form. The one is an import function and the other is a validation function to match a field from the import. Now, I am writing the output of the import to a multiline text box but I have a problem with getting the return value from the matchinh function into the text box. Below the code.
This is the search Function:
private string SearchPcode(string inputStr)
{
string retval = "";
int pcode = 0;
if (!int.TryParse(inputStr, out pcode))
{
retval = "Invalid Integer!";
}
else if ((pcode >= 4731) && (pcode <= 6499))
{
retval = "Eastern Cape";
}
else
{
retval = "Invalid PostCode";
}
return retval;
}
This is the import Function:
private void btnOpenFile_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() != DialogResult.OK)
{
this.Close();
}
else
{
txtboxSelectFile.Text = openFileDialog1.FileName;
}
string filePath;
filePath = txtboxSelectFile.Text;
FileHelperEngine<CsvImp> engine = new FileHelperEngine<CsvImp>();
engine.ErrorManager.ErrorMode = ErrorMode.SaveAndContinue;
CsvImp[] res = engine.ReadFile(filePath);
if (engine.ErrorManager.ErrorCount > 0)
engine.ErrorManager.SaveErrors("Errors.txt");
foreach (CsvImp imp in res)
{
SearchPcode(imp.CallComments);
txtboxDisplay.Text += imp.CompanyCode + "\t" + imp.Caller + "\t" +
imp.Reference + "\t" + imp.Agent + "\t" + imp.CallComments + "\t" + Environment.NewLine;
}
}
I want to display the retval just before the Environment.Newline statement.
Any help please?
Thanks in advance
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
You just need to make sure you store the string that is returned. Currently you have:
SearchPcode(imp.CallComments);<br />
txtboxDisplay.Text += ...
In this case the string is returned, but isn't stored anywhere so it's lost. You need another variable to keep it in.
string searchResult = SearchPcode(imp.CallComments);<br />
txtboxDisplay.Text += imp.CompanyCode + "\t" + imp.Caller + "\t" +<br />
imp.Reference + "\t" + imp.Agent + "\t" + imp.CallComments + "\t" + searchResult + Environment.NewLine;
Or, you could use the method more like a variable and do this:
txtboxDisplay.Text += imp.CompanyCode + "\t" + imp.Caller + "\t" +<br />
imp.Reference + "\t" + imp.Agent + "\t" + imp.CallComments + "\t" + SearchPcode(imp.CallComments) + Environment.NewLine;
In this case the string will be returned, and then stored within txtboxDisplay.Text.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Brilliant SK Genius. Guess that is why the name?
It works. Thanks a ton matey.
Now I can peacefully again.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Kwagga wrote: Brilliant SK Genius. Guess that is why the name?
Not really, there are people who are much, much better than me.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Mr. T and Chuck Norris for example
|
|
|
|
|
Kwagga,
I hate to be "that" guy, but you have some common mistakes in those functions I'll gladly help you with
to start with string retval = ""; is bad in a few ways. In .NET strings can't change, each time you "change" it what really happens is a new string is made and the name (which is a point to the string location in memory) gets referenced to the new string. You can see this when you do the following:
string myString = "Hello World!";
string anotherString = myString What happens is that myString and anotherString are just pointing to the same location in memory.
So when you have
string retval = "";
retval = "my Return value";
return retval; you have useless string objects, which waste resources. Though the waste is very small normally, it can add up.
If you are looping though strings as in this pointless example:
string retval = "";
for(uint i=0; i < 10000; ++i)
{
retval += "a";
} You'd end up with 10000 unreferenced and unaccessible (wasted space) strings, with the 10001 string being your final accessable string pointed to retval
Though this is beside by point, there are better ways to do the above example using a StringBuilder which can change/be changed without making a copy of itself, but this is another topic all together.
You don't want these wasted resources as they can add up and waste memory before they get destroyed by the .NET Garbage Collecter (commonly called the GC)
You don't need to initialize an int's to zero either, even more so since the TryParse() function uses an "out" pass by reference instead of a "ref" means that method doesn't (and can't) use the initial value passed, so the input vale is scrapped and overwritten.
For your first function the following would be about 4 or 5 times better:
private string SearchPcode(string inputStr)
{
int pcode;
if (!int.TryParse(inputStr, out pcode))
{
return "Invalid Integer!";
}
else if ((pcode >= 4731) && (pcode <= 6499))
{
return "Eastern Cape";
}
else
{
return "Invalid PostCode";
}
}
This is using the common practice of "multiple exit points" some people don't like those, but I do
You could use the following if you don't like the muli exit method:
private string SearchPcode(string inputStr)
{
string retVal;
int pcode;
if (!int.TryParse(inputStr, out pcode))
{
retVal = "Invalid Integer!";
}
else if ((pcode >= 4731) && (pcode <= 6499))
{
retVal = "Eastern Cape";
}
else
{
retVal = "Invalid PostCode";
}
return retVal;
}
The reason I don't like this is that you have the extra string object, but one little string isn't that bad if it is easier for you to follow/program.
I've ranted enough at you I guess, but there at lots of these little optimizations you can do to the other function as well. As for your business code in the display layer. I'm not one of the people that think these are to be 100% separated and need to follow those "strict" (and at times HARD even for experienced coders) rules....
|
|
|
|
|
hy everyone!
is it possible to easyly convert date formats into different formats.
what i want to do is to convert a date format from english format to german format or vice versa.
i do have a function which looks like
public static string ConverFormat (string input, string format, string Cultureinfo)
so when entering this function input contains the date, format contains the formatstring, in which format to display (e.g. {"mm/dd/yyyy"}) and cultureinfo contains the cultureinfo (e.g. en-US) to which the input has to be converted to (english or german format).
so let's say input = 01.05.2008, format = {mm/dd/yyyy} and cultureinfo = en-US then the output should be 05/01/2008.
in here how to convert datetime.now into desired format???[^] i found how to format the type of how to display the date. but i want to switch it from dd.mm.yyyy to e.g. mm/dd/yyyy or mm.dd.yyyy (following the the format declared in parameter format).
do i have to do this by hand, meaning parsing the string and change it to the desired format or is there a chance to do this using default functions?
thanks!
Stephan.
modified on Thursday, May 1, 2008 6:25 AM
|
|
|
|
|
|
Please only use ISO 8601 formats -- yyyy-MM-dd
|
|
|
|
|
hi,
I have an application with a few custom controls in it.
My problem is, after loading, if I resize my application it takes a long time for all the controls to rearrange them selvs.
any idea how to make things faster?
tnx
leeoz
|
|
|
|
|
Add to the form constructor after the InitializeComponent() the following:
<br />
this.SetStyle(<br />
ControlStyles.AllPaintingInWmPaint |<br />
ControlStyles.UserPaint |<br />
ControlStyles.DoubleBuffer,true);<br />
|
|
|
|
|
Hi
Im trying to retrieve user properties from active directory.
It successfully gets the first required property, but after that all i get is
'NullReferenceException - Object reference not set to an instance of an object'
Why is this? Here is the code:
DirectoryEntry standardUser = new DirectoryEntry("LDAP://CN=" + txtUser.Text.ToString() + ",OU=Users - Standard Users,DC=mydomain,DC=com,DC=uk", "username", "password");<br />
string sUSN = standardUser.Properties["userPrincipalName"].Value.ToString();<br />
string nastsprofile = (standardUser.Properties["TerminalServicesProfilePath"].Value.ToString());
The bit which gets the userPrincipalName works fine. After that it all goes wrong.
|
|
|
|
|
Well, tha fact that you can get the userPrincipalName means that standardUser is fine, so the problem must be that
standardUser.Properties["TerminalServicesProfilePath"].Value is null. I think you might need a lower case 'T' or something.
I found this similar problem on t'internet HERE[^], where the apparent solution was to use lower case.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Ive followed the link.
And changed it to all lowercase.
And replaced .value with .invokeget.
Still no avail
|
|
|
|
|
OK, i think i have it. I'm quite sure you do need to use InvokeGet. InvokeGet will return an object, so you'll need to cast it as a string.
string nastsprofile = standardUser.InvokeGet("TerminalServicesProfileName") as string;
or
string nastsprofile = standardUser.InvokeGet("terminalServicesProfileName") as string;
or
string nastsprofile = standardUser.InvokeGet("terminalservicesprofilename") as string;
I'm pretty sure one of those should work.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
hello
wich function I can add to this function for having a conference (in voice not msg) between 3 personne at minimum
private void checkConf_CheckedChanged(object sender, EventArgs e)
{
int nBusyCount = 0;
for (int nLineCount = 0; nLineCount < 2; nLineCount++)
{
if (iaxc.OnLineState(nLineCount))
nBusyCount++;
}
if (nBusyCount < 2 && CheckStartConf.Checked)
{
CheckStartConf.Checked = false;
MessageBox.Show("Dial/receive more than one calls and then click start conference check box.");
}
}
|
|
|
|
|
Wow - what a question. How is your computer actually in control of your phone lines ? Looks like you have some sort of API, have you read it's docs ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i'm develloping a softphone with the API AsteriskIaxClient (vb.net).
And i want to implemant a function Conference.
But sorry i don't understand you.
Please help me.
if someone have any idea about this probleme can we help me and thank you
|
|
|
|
|
OK, lets revisit this. You are using a third party API that most people here will not have heard of, in VB.NET. So, you're asking about it in our C# forum, and at first, not even telling us what you're using.
I suggest you read the article I link to in my sig, you obviously have trouble working out how to find the best resources for your problems. Your starting point is the docs for the library you're using, any support forums they may have, etc.
I have to admit that googling the API name gets me four pages, in French. I hope you have the resources to do better, because if the whole web has not heard of this library, odds are low that we will have.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
I'm working with this library AsteriskIaxClient and i wan't to develop a function of conference.
Please if you have an idea about this API help me to implemant this function on my project.
And thank you for your help.
|
|
|
|
|
I create a list view and add icons to all the listviewItems , i can see icon when they are list, and small but when i enable large icon there is only text shown not icon. How can i see icon plz help me out.
|
|
|
|