|
I was wondering how to create a file association in my app. So when the user double-clicks on a saved file (a file that was created using serialization), the program will execute and open the file. Also, how can a file icon association be created in the registry? I wasn't able to find to much on the web doing a search. Any help greatly appreciated.
Brian
|
|
|
|
|
This need to be done as part of your setup routine, like an installation program. Visual Studio .NET has a deployment project that makes this very easy.
Otherwise, read Creating a File Association[^] in the Platform SDK.
Your setup routine should not hard-code the path to your executable. Using VS.NET's Windows Installer project you can associate your executable file with the extension so that the right path is used. In less "automated" setup environment you associate the executable's file path with the target application for that file extension. Just try it out. It's quite easy.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Ladies and Gentleman,
How can I create a relative path in a .config file? Basically so I can tell the logging project im using to insert the log at the applications location\log.
Thanks,
Ryan
|
|
|
|
|
What's in the config file has nothing to do with how it's interpreted. The logging project's IConfigurationSectionHandler must understand relative paths and treat them as such. Only the project documentation can tell you whether or not it's supported, but since you didn't tell us what logging project you're even using (assuming it's a public release) we can't really help you.
It's the logging project that handles relative paths or not. What's in the .config file is just data.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Im using log4net, with the file appender, which has you specifically put the path of the log file to be created in the file appender. Unless there is a better way of doing it.
|
|
|
|
|
If you have questions about managed (i.e., not as in ".NET") projects - like those on SourceForge - please ask in their forums. For the log4net SF project page, see http://sourceforge.net/projects/log4net[^]. Your question is specific to their project, not to .config files (again, because the .config files contain just data - it's the implementation of the configuration section that interprets that data).
It's mainly for your benefit: you'll get more concise help for a project that offers it than on a general forum. You'll also learn more by looking at their source code, which - since it is on SF - is available in their CVS reposity - which is also viewable online - and more often than not as a separate download.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I had/have the same problem as you, too. I even tried to find the appender at runtime and make its relative path as an absolute, but it already did it itself. I tried to set a config value of "~/MyLogfile.log" and replace the tilde at runtime.
Maybe you could derive your own class from FileAppender and implement that behavior? What you can do is to place placeholders like "${SystemDrive} " in the path and let it expand it during runtime for you. See the docs for details.
--
Affordable Windows-based CMS: www.zeta-producer.com
|
|
|
|
|
Ahh, thats a good idea, thanks Uwe.
Ryan
|
|
|
|
|
Hello
I made a UserControl containing a ComboBox and I want the "Items" property of the combo relayed to my UserControl :
public class MyUserControl : System.Windows.Forms.UserControl
{
private ComboBox cb;
[...]
public ComboBox.ObjectCollection Items
{
get
{
return cb.Items;
}
}
}
This works but the UITypeEditor isn't "string collection editor" as it is for the ComboBox, but "object collection editor".
So basically, it isn't useful at all.
Is there a way i can force the UITypeEditor being a StringCollectionEditor, even though this class seems to be an internal framewok class ?
Thanks,
Etienne.
|
|
|
|
|
have you tried just marking up your accessor with the correct attribute?
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
public ComboBox.ObjectCollection Items
{
get
{
return cb.Items;
}
set
{
cb.Items = value;
}
}
|
|
|
|
|
hello,
thanks for answering. You can't set the Items property of a ComboBox. Your code nearly works, though the values are not serialized so the AddRange isn't added to InitializeComponents(). I'm going to try and find a way to do this.
|
|
|
|
|
to get the code in the designer's InitializeComponent method you also need a ShouldSerializeFieldName method too, so in your case it would be:
protected bool ShouldSerializeItems()
{
return true;
}
Note protected modifier - it doesnt need to be on the public interface of the object.
Alo, your collection will need an AddRange method on it for the IDE code gen stuff to work.
|
|
|
|
|
I have tried ShouldSerialize(...) and DesignerSerializationVisibility attribute with no luck. Apparently, there is no easy way to simply publish the combobox "Items" property in my UserControl, which is sad. Looks like i'll have to make my own Items collection class...
Again, thank you for answering.
Etienne.
|
|
|
|
|
The UITypeEditor has nothing to do with serialization. It's only an editor, hence the name. To get default serialization of your class, use the DesignerSerializationVisibilityAttribute to attribute your property, using the DesignerSerializationVisibility.Content enumeration member.
To customize serialization, implement your own CodeDomSerializer derivative for either your custom collection class or your property and attribute your collection class or property with the DesignerSerializerAttribute using the type of your CodeDomSerializer attribute. Several of the types mentioned above have examples in the .NET Framework SDK, which you can read online at http://msdn.microsoft.com/library/en-us/dnanchor/html/netfxanchor.asp[^] but that is also installed by default with VS.NET and the .NET Framework SDK stand-alone installer.
If you implement your own CodeDomSerializer be sure to set DesignerSerializerAttribute.Hidden or just don't use it at all.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
Is any one know, How to call CreateFileMapping in C#.
Thanks
|
|
|
|
|
|
Hi,
I'm developing a database sincronization application. I developed it and tried it using just console input and output (a simple console application). As the sincronizer is working OK I want to use it from a nice Windows Application.
I created a new Windows Application project, added some controls and I wrote this event handler:
private void Init_Click(object sender, System.EventArgs e)
{
Sincronizer Sinc = new Sincronizer();
Sinc.Start();
}
Sinc.Start() runs all the sincronization tasks. The problem is that when I run it, memory starts growing really fast (from 200Mb to 600Mb in seconds). I really don't know what I'm doing wrong, since the sincronizer object worked perfectly in my console application.
I would really appreciate some help
thanks,
Federico
|
|
|
|
|
Could you post more information on the Sincronizer object? What does the Start method do? Also, when it ran in an console application how was the memory usage?
~javier lozano
(blog)
|
|
|
|
|
Federico Milano wrote:
Sinc.Start() runs all the sincronization tasks. The problem is that when I run it, memory starts growing really fast (from 200Mb to 600Mb in seconds). I really don't know what I'm doing wrong, since the sincronizer object worked perfectly in my console application.
It's really hard to say anything without seeing any code: you could be doing almost anything in there.
You could try to comment out some portions of code until the leak stops, and try to show us a piece of code that's causing the leak.
Yes, even I am blogging now!
|
|
|
|
|
Sorry to say, but that doesn't help us answer your question at all. More code is required since no one here would know what Sincronizer is doing.
Guessing, however, you're probably not disposing connections, commands, or any other object that implements IDisposable . While managed objects are managed by the garbage collector (GC), the GC doesn't run unless 1) your application is idle, 2) your machine is running low on memory, or has been exhausted of all memory, or 3) you call GC.Collect , which is not recommended because it will block your threat while it finalizes objects. Good coding practices can get around that last problem by disposing objects correctly.
So, lets say in your implementation you re-use the IDbConnection implementation (for brevity, lets say you're using the System.Data.SqlClient ) like SqlConnection . Fine, just make sure you open and close it correctly. For each command that you create, however, you need to dispose it when done:
using (SqlCommand cmd = conn.CreateConnection())
{
cmd.CommandText = "insert into MyTable (ID, Name) values (1, \"Bob\")";
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
} The outer using statement makes sure the object is disposed, compiling to the following:
SqlCommand cmd = conn.CreateCommand();
try
{
cmd.CommandText = "...";
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
}
finally
{
cmd.Dispose();
} As you should see, by expanding the try-finally blocks yourself instead of using using , you could eliminate an extra finally block which would improve performance a little in cases when an exception is thrown.
Also, if you're doing batch updates or inserts, use parameterized queries, re-using the same IDbCommand over and over. See SqlCommand.Parameters in the .NET Framework SDK for an example. While I'm at it, never use string concatentation for constructing SQL expressions - always use parameterized queries. This is far more secure (ever heard of SQL-injection attacks? string concatentation is the first step in making them possible) and actually alieviates quite a bit of your work when doing batch updates or inserts.
If you're using a DataSet to synchronize database, then you also need to dispose the DataSet otherwise it won't be disposed until your application is idle or until your memory is exhausted, which will happen long after you see a general drain on system resources (like CPU cycles).
Note that the disposable pattern doesn't mean the GC won't free your objects, like the "managed environment" means, but that you free the resources immediately. If you don't free them immediately it is not gauranteed when it will happen (taking into account the conditions I spoke of above and depending on the collection generation of the objects).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot for your answers. Maybe, I think, I'm hanging the UI thread because the Start() method is sycnhronous and doesn't return until it finishes. This would explain that when I was running this from the Console Application memory consumption was normal.
So, the question now is, how can I call this method without hanging the UI thread?
thanks,
Federico
|
|
|
|
|
Start it in a new thread:
Sincronizer s = new Sincronizer();
Thread t = new Thread(new ThreadStart(s.Start));
t.Start(); There's many other ways, too. Maybe your implementation of Sincronizer.Start starts itself in a thread (but make sure the caller knows to block before exiting; you can use Thread.Join for that). You could use a delegate and use BeginInvoke , and when you want to wait for it to finish you could use EndInvoke (which blocks until done (if not already), and returns any return value.
There is a catch: if you update any controls in your Windows Forms application, you need to use Control.InvokeRequired and Control.Invoke to invoke the method on the control in the thread on which the control was created. See the .NET Framework SDK documentation for either the property or method above for more information.
For more information on threading in the .NET Framework, read Threading[^] in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I've (nearly) written a custom collection implementing IBindingList and ITypedList to use a datasource for the Datagrid.
The collection takes in the constructor the type of object the list will hold.
myCollection vehicleList = new MyCollection(typeof(Vehicle));
Using ITypedListGetItemProperties I then get a PropertyDescriptorCollection of Vehicle as the grid column header source. This all works fine.
However I intended that Vehicle could have a collection.
Public Class Vehicle<br />
{<br />
Class Vehicle(){}<br />
<br />
<br />
private MyCollection peopleList = new myCollection(typeof(People))<br />
<br />
public myCollection PeopleList<br />
{<br />
get{return peopleList;}<br />
}<br />
}<br />
when selecting this sublist as a link within the datagrid I'd like to re-use ITypedList.GetItemProperties to retrieve the public properties of type People.
So far I can identify the PropertyDescriptor for peopleList and it's type of MyCollection, but I can't get the instace of peopleList needed to retrieve it's collection type of People. From which I can then build the PropertyDescriptorCollection for People.
Is is possible to get the instance to which the propertyDescriptor is refering? If not I've wasted a lot of time getting this far
|
|
|
|
|
the last free name wrote:
So far I can identify the PropertyDescriptor for peopleList and it's type of MyCollection...
What exactly do you mean by "I can". Do you mean the code you've written can, you can through the debugger or through Type discovery? Please be specific.
Also, you really only need to implement ITypedList if you need to customize the properties exposed to bindable controls. Controls that implement binding correctly (like those defined in the .NET Framework Class Library) use the BindingManagerBase class for binding, from which CurrencyManager and PropertyManager derive. If you bind your collection of objects correctly (see the DataGridTableStyle.MappingName property for more information and an example) then you get binding for free.
Implementing IBindingList , on the other hand, is a custom feat that really depends on your requirements, but the basic implementation you also get for free. For example, if your collection (or, rather, list) returns true for IList.IsReadOnly then items can't be added and the UI appears appropriately.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am trying to map my ArrayList of type CRelation to data grid. CRelation class has two properties Child and Parent, both are of type CTable
<br />
public class CRelation<br />
{<br />
public CRelation()<br />
{<br />
}<br />
private CTable m_oPrntTbl;<br />
public CTable Parent<br />
{<br />
set {m_oPrntTbl=value;}<br />
get{return m_oPrntTbl;}<br />
}<br />
private CTable m_oChldTbl;<br />
public CTable Child<br />
{<br />
set {m_oChldTbl=value;}<br />
get{return m_oChldTbl;}<br />
}<br />
}<br />
<br />
<br />
public class CTable <br />
{<br />
public CTable()<br />
{<br />
}<br />
<br />
private string m_szName;<br />
public string Name<br />
{<br />
set{m_szName = value;}<br />
get{return m_szName;}<br />
}<br />
}<br />
<br />
Now i want to map the grid column to Name property of the Child
I am using following code to map the property
<br />
DataGridTextBoxColumn dgcCol = new DataGridTextBoxColumn();<br />
dgcCol.MappingName = "Child.Name";<br />
Code above does not work.
Am i doing something wrong here?
Thanks
|
|
|
|
|