|
Here[^] is one. If you search here / google you'll find many others.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
|
Hi everybody.
Just spent some very frustrating houres fighting with Vista.
Wanted to know, what exception I get, when I write to a folder where I hav no rights. OK - just some lines and I'll see:
StreamWriter sw = null;
try
{
sw = new StreamWriter( @"C:\Windows\System32\MyService\test.txt", true, Encoding.GetEncoding( "windows-1252" ) );
sw.WriteLine( "sometext" );
}
catch (Exception e)
{
MessageBox.Show( e, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning );
}
finally
{
if (sw != null) sw.Close();
}
I took C:\Windows\System32\MyService\test.txt because I was to lazy to change the rights of some testpath and I know (knew?) I could not write there as 'normal user'.
The result: no exception and no file???
what the?
check the path - OK
try to write from cmd (copy con: C:\Windows\System32\MyService\test.txt) - Access is denied. 0 file(s) copied.
So I change the rights for Users on C:\Windows\System32\MyService to Full Access.
Rerun of prog gives the same results???
copy con: now works
After some headscratching and wondering I changed the filename in the program to test2.txt. Now it writes the file. Back to test.txt - no exception and no writing???
Took away Full Access (and write and modify and write) and tried test3.txt. As expected no and no. Back to Full Access - test3.txt no and no, test4.txt no problem.
I created a new folder under System32. Same results as before.
If I do the same with a path like C:\testpath, everything works as expected. Normaly I can write, if I take away some rights (deny write or something) I get my exception (UnauthorizedAccessException by the way)
So how does .NET or something first supress an exception and then somehow remember it later?
Please help
Norbert
PS. please forgive any errors in my english
|
|
|
|
|
Typical Vista crappyness.. did you check whether the file was wrongly and silently redirected to some obscure place?
|
|
|
|
|
I tried, but didn't find it. Any idea where to look? And to prevent it from happening?
|
|
|
|
|
"logical" locations would include My Documents, the application's data folder, and NUL (nowhere, just silently discarded)
It might be more reliable (at least exception-wise) to create and write the file in a temporary place and then move or copy it to System32 (File.Move or File.Copy )
Then again, this is Vista. All bets are off. It has a habit of ignoring bad things silently but complaining loudly about not-so-bad things..
|
|
|
|
|
Nope. Can't find anything. I think I have to check after the first write, that there is something there.
Stupid.
But thanks anyhow.
|
|
|
|
|
At the catch clause in order to show the error message use:
System.Diagnostics.Trace.Assert(false,"Error:" + err.ToString());
OR if running a debug version:
System.Diagnostics.Debug.Assert(false,"Error:" + err.ToString());
Do not attempt to show a message box window when running a service. Your exception line throws an exception.
When writing files especially in vista, you should use Environment.SpecialFolder and not a hard coded path:
string dirPath = Environment.GetFolderPath(
Environment.SpecialFolder.LocalApplicationData);
Natza Mitzi
|
|
|
|
|
Hi
I am able to make both the client and the server to communicate ..
The message from the server is displayed in a listbox control..
I have displayed an acknowledgement message from the server say,"Welcome to the server "in the listbox.
I have also added a label box in a table control
If the received message is "welcome to the server" the color of the label should change...The following code does not give me any error but the color of the label is not changed.Can you spot out the mistake
data = new byte[1024];
int recv = sock.ReceiveFrom(data, ref tmpRemote);
listBox3.Items.Add(Encoding.ASCII.GetString(data, 0, recv));
String gt = data.ToString();
if (gt=="Welcome to the Server")
{
lb9.BackColor = Color.Green;
}
|
|
|
|
|
Hi,
what you need is called "debugging", which includes looking at intermediate values, and possibly rethinking your code.
Did you ever look at the value of gt?
Why is it you use Encoding.ASCII.GetString() to display something, however you use ToString() to compare it to a known value?
This is one occasion where less code will give you a better outcome.
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:11 AM
|
|
|
|
|
Hi
I have modified the code...Still the color does not change
String fr = Encoding.ASCII.GetString(data);
if (fr.Equals( "Welcome to the Server"))
{
lb9.BackColor = Color.Green;
}
|
|
|
|
|
Hi,
is the statement lb9.BackColor = Color.Green; being executed at all? check either by single-stepping or by adding some observation statement (Console.WriteLine("green")) inside the code block.
If it is and it does not show, here are several possible reasons:
- your code is not running on the main thread (then lb9 needs InvokeReqruied/Invoke)
- your code is followed by something that takes long or forever, and sits in an event handler (such as a button click); the GUI effects will show only when its done unless you insert an Applications.DoEvents() which is just a hack, not a recommendation.
- your code is followed by something that changes the color back before the GUI had an opportunity to show the changes.
Learn to debug: add observational code (logging, tracing, MessageBox, Console.WriteLine, whatever) and/or single-step.
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:12 AM
|
|
|
|
|
mrithula8 wrote: String fr
Just changing your variable name rarely affects the outcome of your code. Just as naming your dog one name vs another the dog is still the same dog.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
Expert Coming wrote: Just changing your variable name rarely affects the outcome of your code. Just as naming your dog one name vs another the dog is still the same dog.
I'm going to have to remember that!
|
|
|
|
|
Hi,
just reread your post and now noticed text and code don't match, have a look at the casing of "Welcome" and "Server". You may want to perform a case-insensitive compare, e.g. by using string.Compare(... , ... , true)
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 Saturday, March 7, 2009 4:08 PM
modified on Sunday, June 12, 2011 9:12 AM
|
|
|
|
|
Hi
The message "Welcome to the Server" is sent by the server and is displayed in the listbox.The color of the label changes with a click of the item "Welcome to the Server" in the listbox.But my requirement is that the color of the label should change when the message "Welcome to the Server" is sent from the server and is displayed in the listbox control and not with a click of the listbox item...Is that possible?Can you please tell me how i can go about this?
private void listBox3_Click(object o, EventArgs e)
{
Object df = listBox3.SelectedItem;
String kl = (String)df;
if (kl == "Welcome to the Server")
{
lb9.Text = "Active";
lb9.BackColor = Color.Green;
}
else
{
lb9.Text = "Inactive";
lb9.BackColor = Color.Red;
}
}
|
|
|
|
|
Hi,
1.
AFAIK there is no ListBox event firing when something gets added to its Items, so you will have to modify the code that adds stuff to the ListBox.Items, which probably resides in an event-driven handler anyway (some kind of DataReceived handler I would hope).
2.
The code shown is wrong and ugly for several reasons:
- ListBox.SelectedItem can be null (when nothing is selected), in which case you are switching to Inactive;
- once the server is active, it probably will add more stuff to the ListBox, and everytime that a some new line is clicked, assuming it is different from "Welcome to the Server" it will again declare an inactive state. Remedy: check on the presence of something that signifies end of session.
- what happens if the "Welcome to the Server" message changes for some reason, say extra spaces, carriage returns, etc? Checking for an exact match isn't probably not very wise, I would at least doif (kl.ToLower().Contains("welcome to the server"))...
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:12 AM
|
|
|
|
|
I have an application that queries records from a Visual FoxPro 8.0 table. I created an install project for this application an included the Vfpoledb merge module. When running the installed application on the development computer everything works fine. But when I install it on a Vista computer and try running it comes back with the error 'Cannot register Vfpoledb.1'. I'm installing it under the admin account. Any ideas on how to fix this problem? Thanks.
|
|
|
|
|
hi,
i wanna ask for how to make the .exe file run automatic after finish copy it from a location to another location. the exe file will run automatic without double click on it..
thanks..
- tyrone
|
|
|
|
|
If you mean the exe that is your application then you can't.
If you're moving an exe file within your application, then you can use the System.Diagnostics.Process class and it's Start method to start the exe.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Your can use your code to start it:
System.Diagnostics.Process.Start(anotherlocation+filename);
|
|
|
|
|
Anybody help me
In my application create a clock grid, the clock grid means the 24x7 clock(label) are formed a grid view, so i used the label, the label for every
cell, so totally 168 label are created in a one clock grid,
The two clock grid are created dynamically when the button
will be clicked.
My problem is that take lot time to loading and the GUI
blinking
How can handle this problem or give any other solution to
create this clock grid
Please Help me....
Thank you...
|
|
|
|
|
Create a Control and do your own drawing instead of using 168 labels!
If you've never created one before it's pretty easy. The code below will simply draw the control's Text at it's point 0, 0 using it's ForeColor and Font properties - and sets the default size for the control to 100, 100.
You can use this as a base to get started.
using System.Drawing;
using System.Windows.Forms;
public class ClockGrid : Control
{
public ClockGrid()
{
Size = new Size(100, 100);
}
protected override void OnPaint(PaintEventArgs e)
{
Point textPoint = new Point(0,0);
using (Brush brush = new SolidBrush(ForeColor))
{
e.Graphics.DrawString(Text, Font, brush, textPoint);
}
base.OnPaint(e);
}
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
anishkannan wrote: 168 label
Wouldn't it do displaying a Digital clock with time like 08:02:10 ?? You could easily show date too (08:02:10 08-March-2009)
|
|
|
|
|
TRy not to use so many controls since they consume a lot of resources.
To test the true performance use Release mode and not DEBUG mode.
There are plenty of articles discussing custom controls and overriding OnPaint.
Here is a small sample:
///
/// A custom control
///
public class MyUserControl : UserControl
{
#region Constructors and Initializers
///
/// Initializes the <c>ChartControl.
///
public MyUserControl()
{
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.ResizeRedraw, true);
SetStyle(ControlStyles.Opaque, true);
UpdateStyles();
InitializeComponent();
}
#region Event Overrides
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
{
//Do Nothing
}
protected override void OnPaint(PaintEventArgs args)
{
//Paint logic (first call graphics.Clear(BackgoundColor)
// Start drawing
}
#endregion
}
Natza Mitzi
|
|
|
|