|
Did you set the BodyFormat property of the message to MailFormat.Html?
---------------------
Marshall Rosenstein
.NET Consultant
|
|
|
|
|
No i didn't set that property...
I read your reply, tried it and it works fine !
Thanks a lot !
|
|
|
|
|
I have an application that has a form which is bound to a DataView contained within another object. The form allows be to navigate through the rows of the table in a similar way to the Binding class overview example in the MSDN documentation (i.e. I have two buttons which change the position Property of a BindingManager). Everything works fine until I try and insert a new row. The problem is that while the row inserts just fine, the DataBindingManager doesn't seem to know about it.
Example:
I have two records (1 and 2) and I add one more, the new record becomes record one (because they are sorted alphabetically) and the BindingManager position gets set to 2 (because I was looking at the old record one before). I can still navigate up to the next record (now record 3) and back to record 2 (previously 1), but I can't get to the new record at all. For some reason it won't let me set the Position property to 1!
Sorry if that's a little difficult to follow, but does anybody know what's going on here? I've tried creating a new BindingManger object, but that doesn't seem to work, I've tried recreating the DataView and that didn't help. I tried completely reloading the data from the database and that didn't work. Any ideas????
Thanks
|
|
|
|
|
I've finally hit upon the problem, so in case anybody else encounters this: The problem was that I hadn't bother to set all of the columns in my new row and some of the ones I hadn't set were supposed to be bound to controls. Because the BindingManager couldn't bind all the controls in decided to just ignore my request to go to the new record. I'm not sure if only happens with certain controls. I have textboxes, comboboxes, checkboxes and a datepicker on my form and I suspect it's probably just a subset of those that are causing the problem (probably the checkboxes and maybe the datepicker).
|
|
|
|
|
After a quick experiment I can confirm that it's both the checkboxes and the datepicker that cannot be left null. The textboxes and comboboxes don't care.
|
|
|
|
|
Hi,
I have form in which there is a panel. This Panel is filled with controls from a different .net dll .
I want to serialize this Panel only. If I serialize the whole class in the .net dll it gives me serialization errors for the other fields in the class like Form, Panel and XMLTextReader.
How can I serialize this Panel ?
Thanks,
Paul
|
|
|
|
|
There are a couple ways.
You could override the Panel , add the SerializationAttribute (it doesn't inherit) to it, then implement the ISerializable interface to override serialization (don't forget about the serialization constructor).
You could also use a ISerializationSurrogate (see docs for more details) which allows you to serialize a Type that isn't serializable. It's easy to use. After you create your formatter, set its SurrogateSelector property to an ISurrogateSelector instance, or - if already instantiated - simple add your surrogates. You could either do this for the pre-defined Panel class if you don't want to derive your own, or add surrogates for the types that aren't serializing (with one or more surrogates). Then just serialize or deserialize.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
IS there a place where I can see an example of the kind B'coz it is going to be real complex as that Panel has all kinds of controls within it !
Like Button, Label, ListBox, ComboBox, ListView , actually all controls possible !
So which method do you think would be better in handling this scenario ?
Thanks,
Paul
|
|
|
|
|
Just google for ISerializationSurrogate and see. As far as what would be easier, you could just either derive from Panel and override just the serialization stuff (and then use that Panel class in your code instead of the .NET BCL's Panel ), or use a surrogate on just the Panel type, serializing only the information you want. You could even enumerate the child controls and save the information you want from there instead of having a surrogate for each type, although then you would have to manage the nested objects yourself, which isn't necessarily easy and would most likely include a lot of string parsing.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have a C# app which I want to receive input from other external sources (mainly the OS and IE) when a certain type of file or resource is launched by the user. I.E. if my app is running and someone opens up a file on the OS with the extension ".xyz" I want my running app to receive it (similar if someone clicks on that mime-type in the browser) or it to launch my app and read it if its not running.
I did some hunting around and it seems that if that type is associated with my app in the OS it will attempt to launch my application. I have code in my main method to check to see if a process for my app is already running so I have that covered. However, how do I read the stream coming in to me (standard in threw exceptions) and what is the best way to pass that to my already running app from my main method? I could have my app listening on a port but that seems a bit much. I tried playing with standard in to no avail.
Any help would be appreciated.
PS Also, if someone can inform me of the best OS way of associating my app upon install with both a specific file extension and an IE mime-type that would also be appreciated.
|
|
|
|
|
The System.Diagnostics namespace is here to help!
There is a class called Process . It allows you to use a ProcessStartInfo struct that lets you use the ShellExecuteEx API from Windows that will execute the app (or whatever is the handler) for a file extension, MIME type, etc. Basically, create a new Process object, create a new ProcessStartInfo , fill in the info in the struct and set ProcessStartpInfo.ShellExecute = true , and call Start on the Process instance with the ProcessStartInfo .
Before doing so, the Process class also defines properties for getting a StreamReader for all your standard I/O.
The documentation for the Process class has a lot of good information and examples for everything you're needing to do.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Heath:
I believe you misread the point of his question.
AJB:
If your app is associated with a file extension you will be called with the name of that file as a command line argument, i.e. the args in static int Main(string[] args) , not the stream on standard input.
And file types registrations are stored, unsurprisingly, in the registry. Whatever tool you use to create a install package will have that as an easy option. If you want to do it manually use the Microsoft.Win32.Registry class and read the documentation on shell file types here.
I can no longer find an MSDN reference to the IE mime handler information, but by memory, HKCR/MIME/database/Content Type/{insert your mime type here}/Extension = {make sure it points to the extention you've mapped above}
You can also do fancier things with Monikers and DocObjects, but that would be hard to do with C#.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Thanks to both of you for your response. You both are correct and this info has been helpful except I still don't have enough info. I am aware of reading the file path from the Main method's args but it still doesn't get me where I want to be to deal with the case where I already have a process for my app running (and I only want to allow one process running for this app). The basic logic I want is this:
Main()
check to see if a process for my app is already running (I know how to do this)
if a process exists, send the args to it
else continue running and start my app normally by continuing execution of my main method
From Heath's response and reading the documentation (which is weak on this) it seems that I would have to have my main method start a new Process for my app if its not already running because I need to redirect the standard input. Is that true? And how does the subsequent running of my app, after it finds the already running process, send that info to the process?
Thanks
|
|
|
|
|
AJB... wrote:
From Heath's response and reading the documentation (which is weak on this) it seems that I would have to have my main method start a new Process for my app if its not already running because I need to redirect the standard input. Is that true? And how does the subsequent running of my app, after it finds the already running process, send that info to the process
No, Heath's response is certainly correct, but it is not the correct tool for the problem you are describing. You can not use the Process.ShellExecute or ProcessStartInfo to pass information to an already running process. (Well, not without implementing Shell DDE, which is old, icky and hard to do in C#.)
You can also not pass something as standard input to an already running process.
What you've described already knowing how to do is the correct first step. It sounds like the only part you are missing is how to send the arguments to the already running process if you discover there is one. This is a basic interprocess communication problem and there are many perfectly good solutions. Your main process should listen via .NET remoting or a socket or even just a custom windows message, for filename's to be passed to it. It's hard to recommend which of the many options here to use without knowing more about your application.
Some more advanced things to keep in mind:
~ What happens if a second file of the type you care about is opened while your main process is still handling the previous one?
~ How fast is your main process to load? Should you consider a small stub that actually gets registered to handle the file type and passes the name on to your main worker process?
~ Do you need to process streams as they download in IE, or just get passed the completely downloaded file out of the cache? If so you need to look at URL monikers.
--
-Blake (com/bcdev/blake)
|
|
|
|
|
Ah, I see he posted what he emailed me directly here.
I must've missed that running instance part otherwise I wouldn't have posted that.
What I did mention, however, is that you can use either DDE, but like you said - that's a bit tricky.
Coming from a COM background, I usually prefer the ROT (running object table) for doing this. There is some support in .NET's BCL for this, but you still have to implement various things to make it work. With a document architecture, you could associate a progid with the document type (file extension, for one example) and get an instance of the document type from the ROT. If the document type has a property to get the running app instance, you could then get the instance and load the new doc into the app instance. This means, then, that you have to insert objects into the ROT. There isn't support for this in .NET, but it's not hard to P/Invoke. This is a very simplistic way of doing things (really, it's better to deal with monikers, in which case you could use a simple file moniker) but it requires a pretty good understanding of COM.
It's all about how much you want to write and how much you want to support. If you do use monikers and the ROT, your document app could easily be invoked from COM. With a little extra work, you could implement an out-of-process server, similar to how the Office apps work.
Just my $0.02.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
I would like to learn C# and particulary write an MFC like application in C# :
I need :
- a mainframe with menu, toolbar and status bar
- some documents with associated views (like MFC)
Is it possible in C# to write this kind of application ?
All demo programs I found has a single window (eventually some popup dialog), but never I seen a multi-document C# demo.
Could you give me a start point (example) or doc for this kind of application ?
Thanks in advance,
|
|
|
|
|
The main frame is no problem. Create a new Windows Forms project and drag a menu and toolbar on it.
The doc/view architecture - something MFC was partly designed for - is a bit trickier but not impossible - heck, nothing is impossible given time. There are several articles on CP that I've seen regarding this topic (like using MDI windows which .NET provides built-in support for) that would be worth checking out. In all, though, keep in mind that all .NET apps (because they all compile down to IL, so the source language matters little) have access to everything MFC does (Win32 APIs). Some things are harder, some things are easier.
Also, you'll probably want to dig through the .NET Framework SDK docs - especially the System.Windows.Forms namespace - to see what's available. The docs also include several articles about Windows Forms and some on MSDN that even approach them from an MFC developer's viewpoint. It's always good to know the depth and temperature of the pool (and any creatures that might be lurking in it) before jumping in.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Have a look at Genghis[^] and its sample application.
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
I get this exception when my application wants to delete a file.
the programm load a dll-file from a server and writes the stream into a file with this code:
HttpWebRequest wr =(HttpWebRequest)WebRequest.Create<br />
("http://localhost/Server/Tools/"+strFileName);<br />
HttpWebResponse ws = (HttpWebResponse)wr.GetResponse();<br />
Stream str = ws.GetResponseStream();<br />
...<br />
FileStream fstr = new FileStream(strFileName, FileMode.Create,FileAccess.Write);<br />
fstr.Write(inBuf, 0, bytesRead);<br />
str.Close();<br />
fstr.Close();
but when I start this function a second time (and the session is also running), I get the exception.
so what can I do? how can I stopp using the dll-file to delete it?
|
|
|
|
|
Does anyone have a solution to this problem:
When implementing a ControlDesigner or ParentControlDesigner, if one has a
UserControl that contains child controls as follows:
+========UserControl=========+
| +-----------------------------------+ |
| | Caption Panel | |
| +-----------------------------------+ |
| +---------------------------------- + |
| | Content Panel | |
| +-----------------------------------+ |
+=========================+
My desire is to have ToolboxItems that are added to the UserControl at
design-time be added as children of the ContentPanel.
- Using a ControlDesigner and invoking CreateComponent() adds the control to
the current design document (the UserControl).
- If one attempts to "re-parent" the control being "dropped" within the
designer for the UserControl by doing the following
Control target = ((myUserControl)this.Control).ContentPanel;
// the (child) Control where the dropped control should be moved-to
this.Control.Controls.RemoveAt(this.Control.Controls.IndexOf(ctl));
// remove the control from the UserControl (top-level parent)
ctl.Parent = target;
// assign the .Parent property of the control
target.Controls.Add(ctl);
// add the dropped control to the ContentPanel Controls collection
The error "Object reference not set to an instance of an object" occurs.
Do I need to create a(nother) designer for the ContentPanel so that IT can
serve as the target of the DragDrop? Is there some other (more expedient)
way to do this? Initiate an additional DesignerTransaction that makes the
re-parenting change? Making the .Parent and Controls[] change, and then
using the ComponentChangeService to make Changing/Changed notifications on
the "Parent" and "Controls" PropertyDescriptors ?
|
|
|
|
|
There are ways that you can capture the original parenting the parent it on your user control in the first place. It's been a while since I worked with the designer stuff, but there is a myriad of interfaces (such as and virtual methods (such as overriding OnDropDrop ) and properties I've seen that can help you do this. You could also, for instance, use GetService to get the IComponentChangeService service interface, then handle the ComponentAdding event to determine when a component is about to be added, and add it yourself and ignore the drop. Just a thought.
Also, where is the exception being thrown, exactly? That might give us some better idea of what your current problem is.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Well actually this isn't my exact problem. I didn't feel like typing a whole big mess so I just copied this problem from someone else's post on another site because what he is trying to accomplish is the same as what I'm trying to accomplish:
Allowing a control added to a user control in the designer to really be parented to a child control of that user control whether it be added through a custom verb event, or dropped onto the control...
In my designer for the top level parent I've got some code like this to add a new control to the parent control in response to the use of a custom verb:
<br />
Private Sub OnAddButton(ByVal sender As Object, ByVal e As EventArgs)<br />
Dim b As XPanderLinkLabel<br />
Dim h As IDesignerHost = DirectCast(GetService(GetType(IDesignerHost)), IDesignerHost)<br />
Dim dt As DesignerTransaction<br />
Dim c As IComponentChangeService = DirectCast(getservice(GetType(IComponentChangeService)), IComponentChangeService)<br />
<br />
'Add a new button to the collection<br />
dt = h.CreateTransaction("Add Link")<br />
c.OnComponentChanging(m_XPander, Nothing)<br />
b = DirectCast(h.CreateComponent(GetType(XPanderLinkLabel)), XPanderLinkLabel)<br />
m_XPander.contentpanel.controls.add(b)<br />
c.OnComponentChanged(m_XPander, Nothing, Nothing, Nothing)<br />
dt.Commit()<br />
End Sub<br />
And then in the parent control I handle the OnControlAdded event of the internal panel that I want to be the "true parent"
<br />
Private Sub pnlLinks_ControlAdded(ByVal sender As Object, ByVal e As System.Windows.Forms.ControlEventArgs) Handles pnlLinks.ControlAdded<br />
If TypeOf (e.Control) Is XPanderLinkLabel Then<br />
Me.Links.Add(DirectCast(e.Control, XPanderLinkLabel))<br />
DirectCast(e.Control, XPanderLinkLabel).ImageList = Me.ImageList<br />
e.Control.Dock = DockStyle.Top<br />
Invalidate()<br />
End If<br />
End Sub<br />
This was the first approach that I tried and it did not work because the code was never output. I would get this error at compile time:
".net Code generation for property 'Controls' failed. Error was: 'Object reference not set to an instance of an object."
Essentially I don't care how I can accomplish it, I just want to somehow be able to have the control dropped on the parent control or added through a custom verb to really be parented to the internal control.
|
|
|
|
|
The code you have looks like it might work, but it would be nice to know on which line the exception is being thrown.
Also, the various ideas I gave you should work. I've done similar things to what you're needing before without problems. It's essentially the same concept as what you're doing now, but it uses the design interfaces and properties.
The problem you might be running into is that you're relying on mostly runtime code. While this sometimes works, the code serializer (what actually serializes the design-time code to the source file) might be having problems detecting your changes or giving you instances of what you expect. If you stick with the design interfaces and properties, this shouldn't be a problem (hopefully ).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I've tried some more things and still have not had any luck getting this to work... Do you by chance have any sample code form the times you've done similar things that might serve as a good example?
|
|
|
|
|
No, not anymore.
Did you try getting the IComponentChangeService and overriding how controls are added? There are also virtual methods on the designer classes that allow you to do this. They get called when a component is added. In your designer, override one of these methods and re-site the component. This doesn't rely on runtime code which could be the problem.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|