|
|
shabya wrote: know who triggered the application ?
Depends on how you define "who". Computer Name or User Name?
I Love KongFu~
|
|
|
|
|
hi,
i ment by who : the computer itself on startup or manual activation from srart->programs -> ...
|
|
|
|
|
shabya wrote: the computer itself on startup or manual activation from srart->programs ->
Well, in this case, Environment.UserName is exactly what you are looking for. Jimmanuel already give you the anwser
I Love KongFu~
|
|
|
|
|
why is it not writing to screen the first line/value in the txt file this code?
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class MainClass
{
public static void Main(string[] args)
{
string inFile;
string line;
Console.WriteLine("Input file name to open!");
Console.WriteLine("Sample: d:\\filename.txt");
inFile = Convert.ToString(Console.ReadLine());
StreamReader sr = File.OpenText(inFile);
line = sr.ReadLine();
List<string> lines = new List<string>();
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
foreach (string fi in lines)
{
Console.WriteLine(fi);
}
Console.ReadKey();
sr.Close();
}
}</string></string>
Everything is ok but there aren't first line
|
|
|
|
|
wwwxyz wrote: line = sr.ReadLine(); List lines = new List(); //add all the lines to a list while ((line = sr.ReadLine()) != null)
Because you are reading the fisrt line before the loop and you are not adding it to Lines
Just lines.Add(line); add this before the while loop and after the List lines = new List(); . and it will be fine.
|
|
|
|
|
thanks for reply
Problem is solved but there are two "lines.Add(line);" in code anymore.
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class MainClass
{
public static void Main(string[] args)
{
string inFile;
string line;
Console.WriteLine("Input file name to open!");
Console.WriteLine("Sample: d:\\filename.txt");
inFile = Convert.ToString(Console.ReadLine());
StreamReader sr = File.OpenText(inFile);
line = sr.ReadLine();
List<string> lines = new List<string>();
lines.Add(line);
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
foreach (string fi in lines)
{
Console.WriteLine(fi);
}
Console.ReadKey();
sr.Close();
}
}
</string></string>
|
|
|
|
|
Or you can simply remove the first line = sr.ReadLine(); (which is outside of the while loop) before List lines = new List(); in the original code. (means the code in your first post). I think that line of code is not needed.
and also, its good to check wether the file exist or not before reading/opening. you can implement try-catch block for that.
|
|
|
|
|
just wonderful
thank you very much
I removed the first line = sr.ReadLine(); which is outside of the while loop.
using System;
using System.IO;
using System.Text;
using System.Collections.Generic;
class MainClass
{
public static void Main(string[] args)
{
string inFile;
string line;
Console.WriteLine("Input file name to open!");
Console.WriteLine("Sample: d:\\filename.txt");
inFile = Convert.ToString(Console.ReadLine());
StreamReader sr = File.OpenText(inFile);
List<string> lines = new List<string>();
while ((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
foreach (string fi in lines)
{
Console.WriteLine(fi);
}
Console.ReadKey();
sr.Close();
}
}
</string></string>
|
|
|
|
|
Or simply:
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
class MainClass {
public static void Main() {
Console.WriteLine("Input file name to open!");
Console.WriteLine("Sample: d:\\filename.txt");
File.ReadAllLines(Console.ReadLine()).ToList().ForEach(Console.WriteLine);
}
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
Hi
I am using the Zedgraph addin to plot some curves. I would like to add labels to each curve individually instead of having a legend on the right-hand side. Can anyone shed some light on this?
Thanks,
Alex
|
|
|
|
|
have you consulted Zedgraph genie, I mean, Wikki[^], how about this[^]
Yusuf
Oh didn't you notice, analogous to square roots, they recently introduced rectangular, circular, and diamond roots to determine the size of the corresponding shapes when given the area. Luc Pattyn[^]
|
|
|
|
|
Hi Yusuf,
Thanks for the tip, I have looked there and there is someone else with the same problem but I don't see a solution. There seems to be a function with pie charts but still no idea for line graphs?
Alex
|
|
|
|
|
Hi
I have written a small program to search my computer for certain files. However, I use Vista which has UAC. Unfortunately there are plenty of places where the application can't reach because of permissions. So I decided to search around how to get past the permission problem. I found the following guide:
http://blogs.msdn.com/shawnfa/archive/2006/04/06/568563.aspx
As expected my app now asks when launched to get highest possible permissions when running. Unfortunately, this still prevents me from accessing the same folders. Any suggestions why that is? Have I lost control of my own system or something since it can't even access my own home directory?
|
|
|
|
|
There are folders on the disk that you cannot get to, no matter what accoutn you use. Your code is just going to have to deal with this eventuality.
If you've already made a manfiest file for your app, requesting admin priv's, then that's about the limit of what you can do.
|
|
|
|
|
Dave Kreskowiak wrote: There are folders on the disk that you cannot get to, no matter what accoutn you use. Your code is just going to have to deal with this eventuality.
besides those belonging to other users, what are they?
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
I can't think of a definitive list, but the first that springs to mind is System Volume Information. However, it would be fairly simple to get a list yourself. Just recurse, but print the directory name to the console if you catch an UnauthorisedAccessException. Leave it for a few minutes/hours and you have a list
|
|
|
|
|
Hi Dan,
I don't know them all, I trust C:\System Volume Information and C:\C:\Users\All Users\Start Menu are two of them.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 9:20 AM
|
|
|
|
|
"System Volume Information" for one. I seem to remember there was another folder, but I can't remember the name right now.
|
|
|
|
|
Hi all,
Im not quite sure what i want to use for my problem so i thought maybe somebody out there has a good solution.
My situation is that i have a user control that, for example, displays a list of database entries such as messages. This control can be present in multiple forms that esentially need to be syncrhonised. For example, if an entry is added, edited or deleted in one control, all other controls need to be notified of this and know to look for updates.
As my subject may suggest I have thought of a global event that all instances can listen for, but have not tried yet as i dont know if this is a good option.
Does anybody know of any 'best practice' solutions for this situation?
I usually find my answers with google, but in this instance im not even sure what im searching for.
Thanks
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
If all the events have a similar signature, Delegate.CreateDelegate (starting with .Net v2.0, it supports covariance) and EventInfo.AddEventHandler should help.
However, if you absolutely must use methods with completely different method signatures, then try this approach
|
|
|
|
|
You don't make this a "global" event. This would probably be an event exposed by a singleton data store you create. An event can have multiple subscribers, but since you're sharing data acrossed multiple instances of your control, it would suggest using a central data store to back all instances of the control.
|
|
|
|
|
thanks for your suggestion Dave, i will take a look into it
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Agree with Dave. In your case, no need to create a "complex" global event manager. Just update the UI when you modify the data. Simplicity is always good.
I Love KongFu~
|
|
|
|