|
Kevin Marois wrote: a collection of FolderModels and FileModels I think it would be useful to see the structure/definition of that Collection.
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
I think there is an issue around the xml serialising of complex object, your List<>s make this a complex object. There are literally dozens of alternative serialisers and many articles written on the subject.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yeah just like Microft Mycroft Holmes said. It doesn't let you serialize a collection.
Instead use a foreach and serialize each folder indivitually.
Something like:
using (TextWriter textWriter = new StreamWriter(xmlDataFile))
{
XmlSerializer serializer = new XmlSerializer(typeof(FolderModel));
foreach(folder in Folders) serializer.Serialize(textWriter, folder);
textWriter.Close();
}
All the best,
Dan
|
|
|
|
|
This is a fairly simple one to fix and the error is actually pretty helpful. You told the serializer that you were going to serialize FolderModel but you then try to serialize a list of FolderModel instead.
|
|
|
|
|
SLAP!
That's the sound of me slapping myself.
Thanks!
Everything makes sense in someone's mind
|
|
|
|
|
Hey, no problem. If I hadn't made a similar mistake several thousand times, I'd probably have missed it.
|
|
|
|
|
I find this code a challenge to understand because it appears to me there's a circular (recursive) reference inherent in the structure of the FolderModel class.
Assuming there's no recursion inherent in the data structure itself: all he has to do is to call:
serializer.Serialize(textWriter, FolderModel1); And that's it ?
Your brilliance is shining through again
thanks, Bill
"Anyone who shows me my 'blind spots' gives me the gift of sight." ... a thought from the shallows of the deeply shallow mind of ... Bill
|
|
|
|
|
Hi all,
I got some user filled PDF forms, from there i need to extract the user filled data.Is there any possible way using C# other than 3rd party tool?
Thanks in advance
|
|
|
|
|
No, there is no native support for PDF files built-in to .NET. You'll need to use one of the many 3rd party libraries.
No comment
|
|
|
|
|
|
Thanks for your reply, but i need to fetch the user filled fields.
Is there any way to fetch those field values/tables?
|
|
|
|
|
Hi,
I am hosting an ActivX control in C#. The control has a method as follows...
GetMinMaxVals(bouble* pdMinX, double* pdMaxX, double* pdMinY, double* pdMaxY);
The caller may pass null (zero) for any of the parameters that are not required. I only need a value for pdMaxX.
Question is: How do I pass null for the arguments i do not require?
Thanks - John.
|
|
|
|
|
I don't see a problem. What does your code look like? What have you tried? How does it fail?
|
|
|
|
|
You may need to declare the parameters as IntPtr not ref double. As far as I'm aware it's not possible to pass a null pointer (as opposed to a pointer to null) through a ref or out parameter – it's rather the point of them to stop you accidentally referencing null pointers, after all.
|
|
|
|
|
Thanks for the replies,
@Bob, how would I change the argument type to IntPtr (sounds like it could be a solution), when the method is exposed from the interop dll's generated by VisualStudio?
Thanks - John.
|
|
|
|
|
You have to manually edit the interop C# it produces, I think. I realise this is non-ideal but tlbimp isn't that clever and it makes assumptions (like pointer -> ref) that aren't necessarily valid, so it's sometimes necessary.
|
|
|
|
|
Just change the DllImport decorated function to use IntPtr instead of double :
[DllImport("thedll.dll", SetLastError = true)]
public static extern void GetMinMaxVals(IntPtr pdMinX, ref double pdMaxX, IntPtr pdMinY, IntPtr pdMaxY);
You can then call this like:
double pdMaxX = 0;
GetMinMaxVals(IntPtr.Zero, ref pdMaxX, IntPtr.Zero, IntPtr.Zero);
Change the value of pdMaxX to whatever is suitable for the call. If it only passes a value out and doesn't require one in, then use out instead of ref .
[DllImport("thedll.dll", SetLastError = true)]
public static extern void GetMinMaxVals(IntPtr pdMinX, out double pdMaxX, IntPtr pdMinY, IntPtr pdMaxY);
double pdMaxX;
GetMinMaxVals(IntPtr.Zero, out pdMaxX, IntPtr.Zero, IntPtr.Zero);
If the function returns a value then amend as required.
|
|
|
|
|
So how does the called routine decide which parameters are required and which are not? You could just as easily pass a ref to some special value (0.0, -1.0 etc).
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I'm not confident on this as I obviously don't have the OPs code or API for the ActiveX, but I would guess from the info provided that it looks for null pointers, the .NET equivalent of System.IntPtr.Zero .
I've never looked into this, but doesn't a ref parameter marshal the address at which the actual value is stored, therefore passing 0.0 could pass a pointer to any valid memory address rather than a null (zero) pointer? This could be way wrong - I will research!
|
|
|
|
|
Sorry, I think my comment was not clear. I was suggesting a reference to a variable that contains a specific value that the called method would recognise as a null value. However, the information we have been given seems somewhat less than complete - as is all too common.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
[Read this in conjunction with Davey's reply above]
I'm guessing here, but does GetMinMaxVals just return four doubles through the pointers you pass to it?
If so, then just call it with something like GetMinMaxVals(out double junk1, out double MaxX, out double junk2, out double junk3)
In other words, provide four places for it to put the results, and ignore the three you don't need.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Hi Peter, I am currently doing it the way you sagest, only problem is that it takes time to calculate each value and is making the UI a bit slugg like.
Thanks - John.
|
|
|
|
|
I am looking for either source code or a dll providing a multilingual keyboard for a windows forms C# touchscreen application. This could be either free for commercial use or paid for.
I have spotted the following WEB projects:
1./ A Multilingual Silverlight Virtual Keyboard
2./ JavaScript VirtualKeyboard
but need something non WEB based.
Any pointers would be greatly appreciated.
|
|
|
|
|
Hi,
I need my windows service to execute a routine depending on how old an entry in the Application event log is, i.e. if the last recorded event id (set by the routine) is older than 12 hours then run the routine again...
so, routine runs and writes...
if (!EventLog.SourceExists("mylog")) EventLog.CreateEventSource("mylog", "Application");
EventLog.WriteEntry("mylog", "routine run" , EventLogEntryType.Information,123456);
then, based on a timer...
DateTime lastexe;
EventLog eLog = new EventLog("Application");
foreach (EventLogEntry entry in eLog)
{
if (!entry.EventID == 123456)
{
List<datetime> lastrun = new List<datetime>();
lastrun.Add(entry.TimeWritten);
foreach(entry.TimeWritten in lastrun)
lastexe = lastrun.FindLast;
}
}
DateTime shouldrun;
DateTime rt = DateTime.Now;
if(rt > lastexe.AddHours(1))
{
}
As always, your help is appreciated.Thanks.
|
|
|
|
|
CCodeNewbie wrote:
Yup.
CCodeNewbie wrote: foreach(entry.TimeWritten in lastrun)
"entry.timeWritten" isn't a valid variable-name. This is the variable you can use in the loop. It also requires a type for that variable. Since your list is filled with DateTime objects, we can safely assume this type;
foreach(DateTime someDate in lastrun)
CCodeNewbie wrote: lastexe = lastrun.FindLast;
<a href="http://msdn.microsoft.com/en-us/library/5kthb929.aspx">FindLast</a>[<a href="http://msdn.microsoft.com/en-us/library/5kthb929.aspx" target="_blank" title="New Window">^</a>] returns the last item in the list that qualifies the conditions given.
Try something along these lines;
foreach(DateTime someDate in lastrun)
{
if (someDate > lastexe)
{
lastexe = someDate;
}
}
Using LINQ, that code would be effectively reduced to;
DateTime lastexe = lastrun.Max();
Bastard Programmer from Hell
|
|
|
|