|
I have a C# installer class and I want to retrieve the ProductCode property within the code. How do I do that?
Thanks in advance.
|
|
|
|
|
I'm guess that you mean you added an assembly with an Installer class (attributed with the RunInstallerAttribute class) as a custom action within a Windows Installer package using VS.NET (or anything, really)?
If so, you have to pass it as a command-line parameter. In the Installer class, you can query command-line parameters easily using the Context.Parameters property. It's a simple dictionary. So, lets say you define a command-line parameter named "ProductCode", you'd access it like so:
public override void Install(IDictionary stateSaver)
{
string productCode = Context.Parameters["ProductCode"];
if (productCode != null)
{
}
} In the custom action command-line within the designer for the VS.NET distribution package (an MSI), add /ProductCode=[ProductCode] to the command-line. That will pass-in the ProductCode for the MSI as a command-line argument.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
I am writing some business classes and want to use an enumeration for one of the properties. I am not sure about how to organize the code. I was going to put the enumeration into a separate file:
namespace MyNamespace
{
using System;
public enum EnumDayType : int
{
Weekend= 1,
Holiday = 2
}
}
Then in my class file:
namespace MyNamespace
{
using System;
public class DayType
{
private EnumDayType dayType;
}
}
Is this the correct way to organize my code across files? What are some of the naming conventions for the enumerations (should I preceed the name with Enum, for example)? Should I have a separate source file for each enumeration? Any other suggestions? Thank you.
|
|
|
|
|
It actually doesn't matter: there's no notion of source files when you compile (only in a PDB - programming database - which is used for debugging and is not typically generated for release builds).
Personally, I either define an enum in the class's source file that uses it if it's the only place where it's used, or have a file in my project just for enums used throughout the namespace for that project. You could use a separate source file, though; like I said, it really doesn't matter.
Use whatever organization makes sense to you, unless you're in a team environment; then the team must decide what works best for them.
The only real recommendations that the Visual Studio .NET and .NET Framework SDK docs assert is naming conventions. Read Design Guidelines for Class Library Developers[^] in the .NET Framework SDK for more information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
i follow the article http://www.codeproject.com/csharp/tcpclientserver.asp
to obtain a client/server program and the code work well ... but thers's a tiny problem that the server accept the client then the client send the msg ; then what the client don't respond to any other messages from client
so what a peace of code i shoud modify so the server accept many messages as well in the current connection with out need to restart server .
thx in advanc..
ADEL K Khalil
|
|
|
|
|
If you have a question specific to a particular article, you should ask your question in the article's message board at the bottom of the article.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have written an application that runs on Windows Service. It runs fine (I overcame some of the problems I had with it earlier). It does perfectly everything that it is supposed to do - the only problem - after I start the service it runs for about a day or two and it halts (stops) by itself in the middle of the night. When I see it is stopped, I restart it and it gets back to its normal operation. I have to keep watching until it stops again. Is there known issue that can resolve this problem. Help would be highly appreciated. (vinayakkatkam@yahoo.com).
Vinayak Katkam
|
|
|
|
|
What problem? You didn't give a specific problem and we know nothing about your code so how can we diagnose it?
If you want to know what is happening with your service, you need to debug it. Since this problem takes a while to occur, the best way to debug it is to instrument it. The most basic way is to use the Trace facilities in System.Windows.Forms using the EventLogTraceListener . You can configure this progammatically or using the .config file for your Windows Service (which I recommend, since you can change it at runtime).
Throughout your code, use Trace.WriteLine to log state and events in a reasonable way so that when a problem occurs you can determine either what happened or in what part of your code the problem happened.
In your .config file (named the same as your application + .config and in the same directory, like MyServiceApp.exe.config), write something like this:
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="System.Diagnostics.EventLogTraceListener, System"
initializeData="Application" />
</listeners>
</trace>
</system.diagnostics>
</configuration> Then whenver you use Trace.Write or Trace.WriteLine (or even the corresponding methods on the Debug class, which is only compiled into your IL if the DEBUG symbol is defined by the compiler) the message will appear in the trace log (use eventvwr.exe to view it).
There are other, more complex (and better) ways of instrumenting your application but this is by far the easiest. It's a good place to start, especially since you gave us no specifics with which we can help you.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In addition to Heath's useful suggestions, here is an alternative.
1. Write your code in a regular console/windows application, run and debug your code from the Visual Studio debugger (set break points at places where failures occur).
2. When it is "bug free", run it from XYNTService[^].
If you cannot figure out the bug but you have to deploy your app anyway, then you can use XYNTService to restart your app whenever it fails. Read the above article for details.
P.S. I understand this may not be a good solution under all circumstances.
My articles and software tools
|
|
|
|
|
Is there a means in which FolderBrowserDialog can select other computers that are browsed to? (Directories under remote computers can be selected but the machines themselves cannot). If not, is there some other class/mechanism that can accomplish this?
|
|
|
|
|
They can be, but you can't use the FolderBrowserDialog component in .NET 1.1 and newer. You must P/Invoke SHBrowserForFolder yourself and specify BIF_BROWSEFORCOMPUTER (0x1000) in the BROWSEINFO.ulFlags struct field.
There's no easy way to do this, however, since the FolderBrowserDialog doesn't expose any sort of Flags property. You might either search the CodeProject site (here, of course) for examples of someone who has or use a decompiler/disassembler like .NET Reflector[^] to see how the current FolderBrowserDialog works (it isn't easy, and require knowledge of P/Invoke and shell programming, though copying the code as-is may help).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I have a list of project files (all full path and name)
and I want to create a new solution and then add all these projects to this solution.
This is what I tried.
EnvDTE.Solution mysol = new EnvDTE.SolutionClass();
mySol.Create(@"C:\temp", "dummySolution.sln");
foreach(string myProj in _Projects) //_Projects is a list of project files)
{
mySol.AddFromFile(myProj, true);
}
mySol.Save(@"C:\temp\dummySolution.sln")
The application keeps on busy for a while and then I get a System.Runtime.InteropServices.COMEException
Additional information: Server execution failed.
Can anybody tell me what is wrong or what I should do instaid.
Thanks in advance,
Johan.
|
|
|
|
|
Hi,
I want to create a class and its methods at run-time. Users will write the class code in text-box and then use it.
How can I do this?
Savaş Külah
savaskulah@msn.com
|
|
|
|
|
|
I'm trying to create my own DLL as a part of interpreter. I'm having trouble to load the dll...
The DLL source code is (TestDLL.dll in system32 directory):
using System;
namespace StringDLL
{
public class DllStringTest
{
public string StringReturn(int value)
{
switch (value)
{
case 0: return "Zero";
case 1: return "One";
case 2: return "Two";
case 3: return "Three";
default: return "Unknown";
}
}
}
}
and in the main code I use to load the DLL is:
[DllImport("DllTest")] public static extern string StringReturn(int value);
then to call the function in the event handler:
MessageBox.Show(StringReturn(0));
I'm trying to return the string value from DLL library. I have been getting the error "unable to find the entry point in TestDLL dll."
I want to load dll only when needed. Can anyone help?
|
|
|
|
|
Hi,
The DllImport attribute is used when using functions exposed by non-.NET libraries. In order to use the assembly you're creating (TestDll.dll), you need to add a reference to it in Visual Studio .NET.
AFAIK, the assembly will not be loaded until you call anything located in it, so there's no no need to implement dynamic loading.
Regards,
Serge (Logic Software, Easy Projects .NET site)
|
|
|
|
|
DllImportAttribute is for calling native functions from native DLLs. Your code is managed code and the only entry point exposed is for the static Main method (by default, which is a compiler feature) of a .EXE assembly.
.NET assemblies you simply reference like you do System.dll, System.Windows.Forms.dll, etc.
In your project where you want to call StringReturn , right-click on your project and select Add Reference. If the project is in the same solution as your other project, click the Projects tab and double-click the project to add it. Otherwise, select or browse to the assembly that defines that method and add it to your project. Then use the fully-qualified class name (or add the namespace to your using statements toward the top of your source file) and call the method. Since it's an instance method, you'll need to instantiate DllStringText .
If you're trying to call arbitrary methods in any assembly dropped into your process's current working directory, you'll need to implement more of a plug-in style application, which usually uses an interface or abstract class to provide abstract access to an implementation and a way to find that implementation. Searching through an assembly is far too expensive to find such types (though possible), so one usually uses a .config file and custom IConfigurationSectionHandler implementation to register types (this is used for the provider pattern-style of programming).
Try the following search for several good plug-in articles:
http://www.codeproject.com/info/search.asp?cats=3&cats=5&searchkw=plug-ins[^]
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
To clarify this... I would need to have the dll be explicively load the dll. I would like to avoid using the "Add Resource" in the .net editor.
|
|
|
|
|
Update:
I tried replacing "AfterSelect" with DoubleClick, but when I compile I get this error:"D:\Documents\Visual Studio Projects\WindowsApplication5\Form1.cs(70): Cannot implicitly convert type 'System.Windows.Forms.TreeViewEventHandler' to 'System.EventHandler'
" from this line: "this.treeView1.DoubleClick += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_DoubleClick);". I tried casting this.treeView1.DoubleCLick to a TreeViewEventHandler, but it won't let me do that either. Any suggestions? (sorry, I'm very new to C#) Also, would it be possible to change the event from DoubleClick to when the user presses the "Enter" key? If so, what is the event for this?
Thanks,
Justin
Original Question:
I am relativley new to C#, and I'm trying to write an app, using the compact framework, that will allow a handheld user to scroll through a treeview, hit enter on a selected node, and then do something specific to that node. I figured that the doubleclick event was as close as I could get to actually pressing enter/return, but I still cannot figure out how to write a method that is specific to a node of the treeview, rather than the entire treeview. When I doubleclick on the treeview in design mode, regardless of what node I click on, the only code it creates for me is private void treeView1_AfterSelect(...). So, does anyone know how to setup a function that will do something when the user doubleclicks/hits enter on a node of a treeview? Examples are much appreciated.
Thanks,
j1e1g1
|
|
|
|
|
Take a look at the TreeView.AfterSelect Event[^] documentation on MSDN. The TreeViewEventArgs contain a Node which you can refer to within your method as the selected node.
private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeNode node = e.Node;
if(node != null)
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Since the TreeNode doesn't fire any everys, you can't wire up any code to it. The DoubleClick event is fired by the TreeView control, not the TreeNode you clicked on. In your DoubleClick event handler, you'll used the SelectedNode property to find out which node the used clicked on. You can modify the function that the designer creates by renaming the treeView1_AfterSelect function to treeView1_DoubleClick and making the same change in the Windows Forms Designer gnerated code section. A search and replace for "AfterSelect" ought to do it nicely.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I tried replacing "AfterSelect" with DoubleClick, but when I compile I get this error:"D:\Documents\Visual Studio Projects\WindowsApplication5\Form1.cs(70): Cannot implicitly convert type 'System.Windows.Forms.TreeViewEventHandler' to 'System.EventHandler'
" from this line: "this.treeView1.DoubleClick += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_DoubleClick);". I tried casting this.treeView1.DoubleCLick to a TreeViewEventHandler, but it won't let me do that either. Any suggestions? (sorry, I'm very new to C#) Also, would it be possible to change the event from DoubleClick to when the user presses the "Enter" key? If so, what is the event for this?
Thanks,
Justin
|
|
|
|
|
Oooops... My mistake. That line should read:
this.treeView1.DoubleClick += new System.EventHandler(this.treeView1_DoubleClick);
There is no specific event fired for the Enter key. You might want to look into handling the KeyPress event, or KeyDown/KeyUp events, or possibly the Click event, to see which one will suit your needs. You can do this easily enough by displaying a MessageBox when those event fire.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
This line:
this.treeView1.DoubleClick += new System.EventHandler(this.treeView1_DoubleClick);
Still throws an error, because I'm not passing this.treeView1_DoubleClick any parameters. I'm not sure what I should pass here, other than (?nulls), because I don't have a sender object or an event arg to pass it.
Here is the error:
Method 'WindowsApplication5.Form1.treeView1_DoubleClick(object, System.Windows.Forms.TreeViewEventArgs)' does not match delegate 'void System.EventHandler(object, System.EventArgs)'
Sorry if this seems elementary, I'm still learning..
Thank you for your patience and your helpful responses,
Justin
|
|
|
|
|