|
Hi,
I want to use resource files to store message box strings. I already read that I can, by defining Name = value pair in text file. like ex > Close = "Really wann quit this application". But now the problem is where should I wirte this text file and then where should I compile Resgen myResource.txt , to create myResource.resource file. Now after doing all this how should I use these Name of string in my application to call resource file. Thanx for ur support.
Inpreet Singh
|
|
|
|
|
Read about the ResourceManager class in the .NET Framework. I already gave you a "walk-through" of how to use it. The class documentation for ResourceManager even includes an example.
BTW, it's better to use ResX files (just XML documents) because you can specify a Type so that you can serialize more than just string (you can serialize anything with an associated TypeConverter like Size , Point , enumerations, etc.).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I have a Win32 service written in C# that I want to create a front-end for (display status, progress, etc.). It would be nice to have a web-interface, but that whole asp.net thingy is a mystery to me (only if I could read!!!).
How should I do it? Actually, How can I do? Remoting? Web-service? So, if Win32 Service = Server, ASP.NET = Client! How to do?
Thanks,
Johnny
|
|
|
|
|
First, learn about ASP.NET by reading the .NET Framework SDK and sites like http://www.asp.net[^]. Don't just jump into something without knowing anything about it.
Second, you can use various ways to control your service. If the user under which ASP.NET runs has the necessary privileges, you can use the ServiceController class to execute commands on your service (so long as you override ServiceBase.OnCustomCommand ). You could also host a Remoting object from your service and communicate with it from ASP.NET, but you should also read about .NET Remoting because it is a difficult subject. You can read more about it in the "Microsoft .NET Remoting" book from MS Press[^] or from Ingo Rammer's[^] .NET Remoting book. Remoting will give you far more control than executing commands on a service (see the documentation for ServiceBase.OnCustomCommand and you'll see why)..
Keep in mind, however, that privileges here are important. By default, ASP.NET runs as the ASPNET local user. By default, this user account is VERY limited (as it should be). You'll have to make sure it can manipulate the service either by running the service as ASPNET (or whatever user you use if you change the machinePolicy section of the machine.config file) or giving ASPNET impersonation privileges and impersonating the account that the service runs as. Depending on your environment, code access security might also hamper your ability since the web application will need the ServiceControllerPermission and SecurityPermission assigned to it with the appropriate arguments (see the ServiceController.ExecuteCommand method for details).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I was looking for something similar, but another way around.
I need to have windows service written that communicates with asp.net application.
I need that service to set some (complex datastructure) variables in asp.net application object.
Is it possible?
|
|
|
|
|
No, not easily (and do I mean HARD, since it would require using Directory Service Objects (DSO) to get the application and a bunch of other code to get the ApplicationState ). The easiest thing to do is to handle the Application.Start event (already hooked-up for you in your Global.asax or Global.asax.cs file) and query to get data for the application, whether that comes from a database or what. If you need to change this at runtime, another way would be to use a file (say, for example, an XML file) and store that in a cache object with a CacheDependency so that when you change the file the cache is invalidated and the data would be read next time, something like:
protected void Application_Start(object sender, EventArgs e)
{
HttpContext current = HttpContext.Current;
if (current != null)
{
Cache cache = current.Cache;
XmlDocument doc = cache["MyStuff"];
if (doc == null)
{
doc = new XmlDocument();
string path = Server.MapPath("/data/mystuff.xml");
doc.Load(path);
cache.Add("MyStuff", doc, new CacheDependency(path),
Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,
CacheItemPriority.High, null);
}
}
} There's many other ways you can accomplish something like this without using services or remoting too.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for the response Heath. What I am looking for is not controlling the service (thru ServiceController), but to have the UI (whatever that may be) commuinuate with my worker threads in the service. Ignoring the difficultes of Remoting, do I use it in an ASP.NET just as I would in any other application type?
|
|
|
|
|
As I mentioned, you can use the ServiceController to execute commands if your ServiceBase -derived services overrides the OnCustomCommand . You still need an instance of the ServiceController for your service (using the service's registered name, not the display name) in order to call ServiceController.ExecuteCommand . Your commands are limited to passing an int , so you'll need to establish an identification protocol, like 0 = Kill threads or something like that. If you use bitwise operations, you could even use this int to have threads sleep for a time, such that the mask 0x80000000 indicates that threads should sleep while the mask 0x0000ffff gets the amount of seconds (or milliseconds, or whatever) to sleep.
If you need more control beyond that, you'll need to use remoting. You can use ASP.NET as a remoting client, but I wouldn't recommend it unless you're using a singleton pattern for a server-activated type (which would be the most likely choice anyway).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I wonder how to get the information of a file of dbf in c#.
For example,record numbers,the header information of file ,record data ,etc.
|
|
|
|
|
i have application that open word document when the user open the applicatoin and try to open another document from the application, the application starts new instance by shell command and passes the file name as parameter.
the problem is i always get the message "can not find the file specified"
but when i deguged the application and copyed the command string and tryed to ru it from the prompet it worked well.
here is my code:::
/////////////////////////////////////////////////////////////////////////////////////
string action="";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
string path = Environment.CurrentDirectory;
int pos=ienum.Current.ToString().IndexOf("bin");//get the first parameter
action=path+"\\Almogahed.exe "+ienum.Current.ToString().Substring pos+12);
ienum.MoveNext();
action+=" "+ienum.Current.ToString().Substring(pos+12);//get second parameter
proc.StartInfo.FileName=action;
proc.Start(); // file can not found why!!!!!!!!!!!!!
/////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
thank u
i did it by using
/////////////////////////////////
proc.StartInfo.Arguments=param;
/////////////////////////////////
|
|
|
|
|
How to set the focus on the treeview nodes for placing the Text in Drag Drop functionality.
I used Drag_Enter event in which , the
treeview.SelectedNode = treeview.GetNodeAt(e.X, e.Y) but
the treeview.SelectedNode always returns Undefined Vaule.
Also, wherever the treeview control was placed , instead of e.X , i used
e.X - treeView.Left and e.Y - treeView.Top
Still, i am not able to get the solution.
Can anyone look into this.
Thanks and Regards,
Viru
|
|
|
|
|
Never set the TreeNode under the cursor while dragging to the SelectedNode . It is NOT the selected node. Instead, you'll have to override the painting and - while dragging (which you can set a flag for instance) - paint the node under the cursor using the highlight colors and any appropriate colors from SystemColors .
The TreeView in the .NET FCL is very limited, and you often have to go to a lot of work for something like this. I recommend you look into tree controls like those from http://www.devexpress.com[^] and http://www.infragistics.com[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello buddies,
I am developing a web control, whose class is derrived from System.Web.UI.Control class. as you know Control Class doesn't include "Style:CssStyleCollection" Property which exists in System.Web.UI.Webcontrols.Webcontrol class. In the latter class this property is magically filled with 'styl'e attribute available in the HTML-side control's tag and I would really be thankful if someone tell me how this happens so I implement it in my System.Web.UI.Control based webcontrol.
Also Webcontrol contains Width and Height properties and all derrived webcontrols can be resized on the design surface of VS using resize handles arround their rectangle, I have added custom Width and Height properties to my System.Web.UI.Control based webcontrol and it works in rendered HTML and also in direct property assignment in properties panel and code, BUT on the design surface of VS it can not be resized with the mouse.
I appreciate any help,
- Den to Fly
---
"Art happens when you least expect it."
|
|
|
|
|
Why don't you just extend WebControl instead of Control ? This is the correct way to make your own WebControl so that you inherit all the functionality from WebControl , which you obviously seem to want.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I initially desired to do so but you know Heath, Webcontrol has 'forecolor', 'bordercolor', ... and other properties that I don't need in my Wencontrol at all. I guess Microsoft should have not include all these properties that are not really generic in all webcontrols or I can say better they could include other light weight class that only had properties available to all UI webcontrols.
anyway can you help me to implement 'Style', 'Width' & 'Height' myself?
Thanks
---
"Art happens when you least expect it."
|
|
|
|
|
If you don't need them, don't use them. Nothing says you have to. And if you don't want them to show up in the designer, override the properties and attribute them with BrowsableAttribute(false) and EditorBrowsableAttribute(EditorBrowsableState.Never) , which is very common in many classes throughout the entire .NET FCL.
If you want to do it the hard way, the Width and Height are simple properties that store the width and height either in private fields your class can use or - more commonly - in the ViewState . The Style property is a little extra work but there are classes in the respectible ASP.NET namespaces that can help you parse and resolve these. Just read the documentation for the namespaces and browse the classes.
Seriously, though, just hide the members you don't want to support from the WebControl base class. You'll save yourself a lot of work. For example:
public class MyWebControl : WebControl
{
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public override Unit Width
{
get { return base.Width; }
set { base.Width = value; }
}
}
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
nt
---
"Art happens when you least expect it."
|
|
|
|
|
Hi,
I have a control I am making (inherits from Control), called ExtendedListView, in which I use two sub controls to perform drawing operations in. Problem is, in these sub controls (which are classes inheriting from Control, inside of ExtendedListView), when I call this.SetStyle(ControlStyles.DoubleBuffer, true), an exception is thrown (not on that line, but sometime after) in System.drawing.dll.
If I call DoubleBuffer in the main class (ExtendedListView), everything is ok. If I delete the DoubleBuffer code from the sub-controls then everything is ok. However, I need these sub-controls to have DoubleBuffer as I am using them to draw into.
I can't see where the exception is because it happens somewhere not in my code. Does anyone know of this error? Why is it happening?
Thanks!
Yaron
|
|
|
|
|
One easy way to get missed exceptions is to wrap the code inside of your
static void Main() function with this:
try
{
}
catch (Exception err)
{
System.Diagnostics.Trace.WriteLine(err.ToString());
}
With that, you should get a detailed report of the error information, which is always a help.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
Thanks John,
Here is what comes up:
System.ArgumentException: Invalid parameter used.
at System.Drawing.Graphics.EndContainer(GraphicsContainer container)
at System.Windows.Forms.DibGraphicsBufferManager.ReleaseBuffer(GraphicsBuffer buffer)
at System.Windows.Forms.GraphicsBuffer.Dispose()
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Test.Form1.Main() in c:\documents and settings\yaron\my documents\visual studio projects\visual c#\extendedlistview\test\form1.cs:line 146
|
|
|
|
|
I personally don't have an answer to this one. Sorry.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
Typically, a better way is to handle the AppDomain.UnhandledException or Application.ThreadException events. Putting a try-catch around your Application.Run statement only catches exception that would cause the message pump to terminate.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Right. I just thought that this was easier to explain and understand, and it would get him the error message he needed to see.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
If you look at the dcoumentation for the ControlStyles.DoubleBuffer member, you'll see that the ControlStyles.AllPaintingInWmPaint and ControlStyles.UserPaint are also required to be set to true in SetStyle . This means that you'll have to make sure to call base.OnPaint in your OnPaint override and handle the WM_ERASEBKGND message (if not already handled by the ListView ,w hich you can find out using ildasm.exe) to call OnPaint as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|