|
Hello
I am new to XmlSerializing and I got a problem when trying to serialize a nullable int.
The thing I serialize look like this
private int? length;<br />
public int? Length {<br />
get { return this.length; }<br />
set { this.length = value; } }
But when I serialize this, and it is null, the output looks like this:
<Length d3p1:nil="true" xmlns:d3p1="http://www.w3.org/2001/XMLSchema-instance" />
What I want it to do is, when the int is null, I want it to be ignored and thereby not having any output to my xml-file.
I could make my int to a string and then convert the string to an int whenever I need, but that doesnt seem to be a good solution to me.
So, does any of you know a way to XmlSerialize an int and then if it is null, it shouldt be showed in the xml-file, or a good article/something?
//QzRz
|
|
|
|
|
To play a AVI stream I use this code in c#:
const uint WS_CHILD = 0x40000000;
const uint WS_VISIBLE = 0x10000000;
const int ACM_OPEN = 0x400 + 100;
const int ACM_PLAY = 0x400 + 101;
IntPtr handle = CreateWindowExW(
0,
"SysAnimate32",
null,
WS_CHILD + WS_VISIBLE,
0,
0,
300,
300,
windowHandle,
IntPtr.Zero,
IntPtr.Zero,
IntPtr.Zero);
SendMessageW(handle, ACM_OPEN, streamhandle, id);
SendMessageW(handle, ACM_PLAY, -1, -1);
...
DestroyWindow(handle)
This works fine in XP, 2003,... But in Vista and Longhorn, the stream is loaded (the background is painted), but not every AVI is played, some are, and some are not. Is there something I missed?
|
|
|
|
|
Hi,
just a guess, but what about codecs? Do you have the same codecs installed? Do the movies play with Media Player?
Cheers,
Chris
"Obstacles are those frightening things you see when you take your Eyes off your aim"
- Henry Ford
Articles
Blog
|
|
|
|
|
I do not thing codecs are the problem. Let's take the example of shell32.dll. Here the AVI resource with id 165 is playing in Vista, but the one with id 162 (the Avi one sees when files and/or folders are deleted) is not. When I delete a folder, I do see the animation (so I presume the codec is installed); when I want to play the animation in another window, I only see the background.
|
|
|
|
|
I want to show a dialog box, that I've created in visual studio when data has arrived from a socket.
I'm using Socket.BeginRecive and passing it a callback method OnDataRecieved.
When I try to show a dialog to get user input upon data received it. The dialog works fine when it's opened via a button on the main form.
This is the code I'm using to get the form.
<br />
RestoreDeleteDialog form = new RestoreDeleteDialog();<br />
form.ShowDialog();<br />
After I've called BeginReceive() and the event method has ended (ie it's stopped executing the code I've written and is sitting their waiting for an event such as button click or an incomming packet) it will crash with this error:
InvalidOperationException
"The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone)."
If I change the above code to form.Show(), ie so the form is not modal, (which is what I want the, as I don't want the netcode blocking for user input) form will not load and will just be a white window. I've put break points in the code that I've written and there are no infinite loops or anything like that. This happens after the constructor and the form load events have run, when my code has exited.
I'm thinking this problem is being caused by a problem threading, as BeginRecieve() is presumably going to be running in another thread, but I'm not really sure about the inner workings of the non-blocking socket methods, or about how I might spawn the dialog off in another thread with out it causing this error.
Anyone got any ideas?
|
|
|
|
|
Hello
When drawing on a PictureBox, I try to do something but I don't know if it's possible
In fact I try to do TWO operation in the same process
1- Update the ground image of my PB drawing some new elements using one graphics
2- Add some temporary elements on another layer using another graphics
Below is my code
At the end I do
this.pb_cont.Image = cityImage;
This will save my new ground image but it also hide whatever I draw on the other Graphics
How can I avoid that ?
Is it possible to re apply graphicsT content on the PB
With my poor knowledge I thought to do this :
GraphicsState OldG = graphicsT.Save();
this.pb_cont.Image = cityImage;
graphicsT.Restore(OldG);
BUT the compile do not even recognize GraphicsState ??
What is my mistake ?
Thank for your help
private void DrawCityList(DataSet cityList,SolidBrush AskBrush,int size)
{
cityImage = new Bitmap(this.pb_cont.Image);
Graphics graphics = Graphics.FromImage(cityImage);
Graphics graphicsT = pb_cont.CreateGraphics();
foreach (AddrList cAdr in AddrLst)
{
graphics.DrawEllipse(Pens.Blue, cAdr.X - 1, cAdr.Y - 1, 2, 2);
if (cAdr.active)
{
if (AskBrush != null)
{
graphicsT.FillEllipse(AskBrush, tX - size/2, tY - size/2, size, size);
}
}
}
this.pb_cont.Image
|
|
|
|
|
Hi everyone.
I'm trying to build a session enumeration for a asp.net site, meaning that i can see all live session and their objects of the session, at start i built a IList of httpsession that i add to it the session every time its created, the problem is that when the session has changed(like adding a new object to the session) the list is not updated with the changes it just stays like the same point when it was added. i need a linked collection that a can add objects to it but when the object change it should be seen in the collection too.
can anyone help please?
thanks.
|
|
|
|
|
Ok say you have a column Firstname... I know how to list the column firstname in the list box and it list all the data from that column in every row in the list box.
What I am wanting to do is for ONE Row.. have up to five phone numbers that you can list in the listbox. This is not in any of my books and having problems finding out how to do it.. I would have to probably have columns for phone numbers one through five then use a foreach items in listbox to store the numbers in there.. Can someone direct me on how to do this?
Basically instead of having five textboxes for phone numbers I have just a listbox. Using the display member and value lets you choose a column and list everything in that column for every row. That isn't what I want to do.. thanks in advance.
|
|
|
|
|
I'm working on a network file synchronization program, and I need to set the date modified property on the local system to now.
This is to make it possible to compare the date modified to a copy of the same file on a different system. The times will be different because when a file is copied across the network it's date modified will be set to the date the file was created by copying it. The local file's date modified will set to when ever the file was last modified.
I could probably do this by reading the file into a stream, then writing it out again, but this would obviously be a waste of resources.
Does anyone know how to just change the date modified of a file to the current time?
Thanks for any help
gunner.
|
|
|
|
|
Hi,
the FileInfo class has properties such as CreationTime and LastWriteTime which have
both a getter and a setter.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi,
I tried google and searched the old posts with no success. I have a problem when rendering transparent
PNGs with GDI+ and the C# Graphics class. The image shows am object on a
transparent background. I get ugly artifacts at the object's edge where
the transparency begins. It looks as if there was a 8bit alpha reduced
to 1 bit. Where there wasn't full transparency, the background (I
suppose blue) seems to shine through.
Does anybody know if that's a problem with the image, the gdi+ or with
my programming?? I simply call
g.DrawImage(img, startPos, 0, imageWidth, height);
And please make the solution as easy as possible
picture: http://img518.imageshack.us/img518/9228/unbenanntxm9.gif[^]
Thanks for any reply and best regards,
Jose
|
|
|
|
|
That's a problem with the image. The easiest way to see if is if you've got an image with a white background and you have anti-aliased or smoothed the lines so they look nice when they meet the background. If you then use something like Fireworks' Magic Wand tool which will "crop" away the background then you have the "ugly" edges because the edge has been merged in with the white background.
In your case it looks like Red has been chosen to be the transparent colour, the problem with this is that where the edges of the image meet the background you don't have true red (i.e. #ff0000) but rather a combination between red and white. Thus when the mask is picked only #ff0000 will become transparent.
It can be fixed using Photoshop / Fireworks fairly easily judging by your screenshot. If you open the image in Fireworks and turn down the tolerance of the wand then the ones that are sort-of-red will be included and can be removed, thus leaving a white edge.
|
|
|
|
|
But he does state that he is "rendering transparent PNGs"
A png with alpha channel should render just fine onto any background color.
Using a wand tool to crop the edges away is useful for gif's and such, but PNG's have 255(?) levels of transparency and shouldnt have any problems with antialias.
(But I have no clue whats wrong in this case)
|
|
|
|
|
I think what your thinking of is the alpha components of colours which is essentially transparency, however the wand tool will not dither the neighbouring pixels with varying degrees of alpha component (as far as I know) so in essence what you have is the body of the picture with 0% alpha (i.e. fully opaque) and the borders were dithered previously with red, in this case. The red which was for example #f00 was replaced with #f000 (100% transparent) but the neighbouring ones were left as, well, pinkish.
The only way to correct this would be to manually edit the png, for example (I'm using Fireworks because it's what I know) you can replace the transparency with red and then use the wand tool to select red but turn down the tolerance so that it hopefully removes all the obvious red. For a smoother edge turn the wand to smooth edges as opposed to crisp or hard.
|
|
|
|
|
Your are right i am using a PNG 24 with 255 levels of transparency.
But its not the image that is my problem, for example, in photoshop the png is displayed with all 255 levels of transparency. i think c# somehow converts the image in a lower 1bit alpha channel format but i am not sure about it. if you could just upload an image that is implemented in c# and thats has all 255 transparency levels it would be a big help for me. of course without any artifacts at the boardes.
my second thought is that c# just doesnt support png24 and semi-transparency.
|
|
|
|
|
Hello
I use this code to create users in active directory, and set their passwords:
static void Main(string[] args)<br />
{<br />
DirectoryEntry parent = new DirectoryEntry("LDAP://test/OU=Admins,DC=test,DC=org");<br />
Console.WriteLine("OU: "+parent.Name);<br />
Console.WriteLine("Domain name:" + System.DirectoryServices.ActiveDirectory.Domain.GetCurrentDomain().Name);<br />
string test = "testuser";<br />
for (int i = 0; i < 20; i++)<br />
{<br />
try<br />
{<br />
DirectoryEntry child = parent.Children.Add("CN=" + test + i.ToString(), "User");<br />
Console.WriteLine(test + i.ToString() + ": create object");<br />
child.Properties["name"].Value = test + i.ToString();<br />
child.Properties["displayName"].Value = test + i.ToString();<br />
child.Properties["GivenName"].Value = test + i.ToString();<br />
child.Properties["Initials"].Value = "q";<br />
child.Properties["sn"].Value = test + i.ToString();<br />
child.Properties["sAMAccountName"].Value = test + i.ToString();<br />
child.CommitChanges();<br />
Console.WriteLine(test + i.ToString() + ": commit info");<br />
child.Invoke("SetPassword", new object[] { "!qwe@ASD" });<br />
child.CommitChanges();<br />
Console.WriteLine(test + i.ToString() + ": commit passowrd");<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.WriteLine(test + i.ToString() + ":"+ ex.ToString());<br />
}<br />
}<br />
}
Within the loop, some users are created and their passwords set successfully, and randomly setting password for some users fail with this error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.DirectoryServices.DirectoryServicesCOMException (0x80072030): There is no such object on the server. (Exception from HRESULT: 0x80072030)
--- End of inner exception stack trace ---
at System.DirectoryServices.DirectoryEntry.Invoke(String methodName, Object[] args)
What are the possible causes for this error? and what are the workarounds?
|
|
|
|
|
Any luck?
Luis Fernando Forero G.
|
|
|
|
|
We have solved the issue long time ago, so I don't remember the issue accurately.
But as I remember, it was related to replication. There were multiple domain controllers serving the domain. If first CommitChanges saves data to dc1, the second may go to dc2.
The solution is to add users in batch and replicate the domain controllers then update the password in another cycle.
|
|
|
|
|
hi
how can i attach picture to database ?
working in SQL server 2000 + #C 2005
thank's
|
|
|
|
|
|
I have to revisit a VS2003 project from years ago, but I cannot open it. I installed SP1, but it's made no difference. The message I get is 'Unable to read project xxx. The file xxx.csproj is not a valid project file. The project file is missing the 'VisualStudioProject' section'.
Sure enough, if I create a new VS2003 project, the XML starts with that node. The projects I have do not have that, and are much denser. But, the 'Visual Studio Version Selector' opens it with VS2003, and VS2005 offers to convert it ( then chokes ). Worse still, I tried creating a new project and found I must have some files that are not used, because some classes were declared twice. This is a long time ago, I am really stuck trying to work out how to access these files.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Perhaps the easiest would be to create a new project and add all the code back into it. Alternatively you can try and compare two project files (a valid one with this one) and restructure the corrupted portions.
|
|
|
|
|
Thanks, I was hoping to avoid the former, and for the latter, the csproj files seem to be in an entirely different format, the element it's looking for is the root of the XML document. But, it's not a VS2005 format, either.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Yeah I've got the feeling that VS2003 was a plain text format and VS2005 moved to an XML format which to be honest it makes more sense.
Just a random thought, what about trying SharpDevelop since that can import all the versions as far as I know.
|
|
|
|
|
Cool idea, thanks, I will try it.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|