|
I have a conundrum. I have recently been tasked with using a C# program to extract files from an Access Database. The files, Excel 2002, were stored using the following VBA based that I found on MSDN.
ACC: Reading, Storing, & Writing Binary Large Objects (BLOBs)
Further research found the following code which I thought would be the C# equivalent code so that I could extract the Excel spreadsheets back to a file. The aim of the project is that I could then email them as attachments to a central party in my company for review.
Obtaining BLOB Values from a Database
The VBA code extracts the Excel files back to their original state correctly while the C# extracted files are twice the size of the originals and totally unreadable by Excel.
Help????? What am I doing wrong?
Paul Kennedy
Father/Son/Husband/C Programmer
What else could you ask for?
|
|
|
|
|
Hi Paul,
First, I'm assuming that your code matches exactly with that from the links (except for the data source settings).
Second, I'm assuming that the data in the BLOB was generated by your VB code and not some other software.
In my experience, a size difference of exactly 2x normally indicates an ASCII vs. Unicode issue. Looking quickly at the links you provided, the VB code may actually storing a Unicode (2 byte) value in the database for each byte that was loaded into the string. IF that is the case, the VB code handles this when it reverses the loads the Blob that it had stored previously. However, the C# code is being precise by avoiding any translation to or from a string.
Take a hard look at the actual bytes coming back through the C# blob request. If every other byte is a zero, it is very probable that the VB code stored extra data. To solve this, you could either re-write the correct data into the database, or strip the extra byte from the values returned when the C# code gets the BLOB data.
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
If this BLOB represents text, you can also use the System.Text.Encoding to translate the bytes to the correct text using the encoding that you specify.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi all.
I have the following regular expression pattern that I go t from a book.
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$
The book says this is suppose to validate atleast 1 uppercase, 1 lowercase, 1 digit, no special characters and between 8 and 10 characters. So "hello123" is not valid, but "Hello123" is valid. Unfortunately "Hello 123" or "Hello@123" are also valid, but should be invalid. What is the correct regular expression syntax?
Thanks in advance
|
|
|
|
|
Hi,
In my quick testing, this change achived the desired goal (note that the last "." was replaced with "[0-9,a-z,A-Z]". I don't know all the terms used in working with regular expressions, but I suspect that this answer along with the book you are reading will give you an understanding of the situation!
^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9,a-z,A-Z]{8,10}$
John
"You said a whole sentence with no words in it, and I understood you!" -- my wife as she cries about slowly becoming a geek.
|
|
|
|
|
Thanks John. It worked great.
|
|
|
|
|
Hi All,
How can i convert pdf to txt. Is there any free .NET libraries available.
Mahesh
|
|
|
|
|
There are many libraries available, a couple of which are advertised on CodeProject, like TallPDF. Search the comments in this forum (see the "Search comment" link at the top of the message box) for many previous discussions. There are not many free ones, though, since this isn't just something you throw together in a day.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:
There are not many free ones, though, since this isn't just something you throw together in a day.
As a sample of this, Linux, Mozilla, Mono, Gnome, KDE, OpenOffice and Bochs were all coded by a single guy who was bored on a single rainny afternoon.
Perl combines all the worst aspects of C and Lisp: a billion different sublanguages in one monolithic executable. It combines the power of C with the readability of PostScript. -- Jamie Zawinski
|
|
|
|
|
See my article, Using XML Digital Signatures for Application Licensing[^] for a conceptual overview of using XML Digital Signatures (though you could just as well use a binary signed file, but then you need to write a parser if you need one) to license your application.
As far as generating the numbers, you should probably come up with some kind of sequence for your serial numbers (hence "serial"). You won't have to come up with an algorithm and unique validation algorithm then. Just start with some number and increment, handing out each iteration as you go.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Why are you worried about the character length of the serial number after signing? Signing doesn't change the content that's signed (although you can envelope the signature, but the digest is not changed). If you sign your serial number, the serial number is not changed. You merely verify that the serial number hasn't changed by checking the signature, which uses a digest.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
In order to decrypt the data, you would have to store the private key in the application! You might as well give it to your competition, especially if this is a managed application in which all they have to do is use ildasm.exe to extract absolutely everything. My article mentioned something along these lines.
You private key must remain private. You can't decrypt without it, so you shouldn't include it in your application. This is the concept my article talks about - something pretty common in application licensing - signing a document with personal information keeps it unique to a person or machine. You verify that the file exists, verify the file hasn't changed (hence the digest and signature), then verify that the signed information is correct (like the computer name or MAC address is the same). None of this requires a private key, so your private key is kept secret (as it should be).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
We've looked into their product and it is very good. Why not use it?
In any case, they use the same concepts that my article discusses. In this case, however, the serial number is used as the validation key or the IV (initialization vector), not sure exactly which. You still have a private key such that you're the only one that can created signed files.
I recommend you at least download their trial and try it out. As I mentioned before, even signing a serial number isn't enough; you must also collect some sort of identity information to tie that serial number to a particular persona, machine, or domain. Otherwise, nothing is stopping someone from giving just the license file to someone else and it will still work without such identifying information.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi All,
.net doesn't has common dialog box for functionality "Open With"
How do I display it in the application if the file type is not registered to open by default with any application?
Can anybody give me any pointers
Thanks & Regards
Shailaja
|
|
|
|
|
Use the ProcessStartInfo and Process classes like so:
ProcessStartInfo info = new ProcessStartInfo("filename");
info.ErrorDialog = true;
info.UseShellExecute = true;
Process.Start(info);
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi All,
How do i maximize my form to full screen on click of button and bring it back to normal when i press ESC.
Like what we see in word application on clicking view-FullScreen or pressing F11 key on IE.
Catch is that when full screen is invoked all the menus and toll bars get hidden.This is the effect i want.
Any help/suggestion would be appreciated.
Thanks
God Is Great
|
|
|
|
|
Hi!
Try this:
Add this lines of code to your EventHandler (e.g. your button for switching to fullscreen):
<br />
OldPosition=new Point(Left,Top);<br />
OldSize=new Size(Width,Height);<br />
Left=0;<br />
Top=0;<br />
TopMost=true;<br />
FormBorderStyle=FormBorderStyle.None;<br />
Width=Screen.PrimaryScreen.Bounds.Width;<br />
Height=Screen.PrimaryScreen.Bounds.Height;<br />
When you click on your button, your window becomes topmost and gets maximized.
To switch to normal view of your window, restore OldPosition and OldSize .
|
|
|
|
|
Hi,
PLz refer the way IE or word application maximize to full screen ..
All the menus and toolbars are hidden..
how is this done..
do we explicitly need to enumerate all the windows and get thier handles and hide all the control!!!
Plz suggest..
God Is Great
|
|
|
|
|
I've got an interface i've constructed in C# for a COM object, IShellFolder. Now I need to construct a pointer to an address that will be used to store the IShellFolder interface.
The problem is, that i have not got a clue how to do this. If it was a structure or base type, i would construct a new one and marshal it, but I don't know how this works for Interfaces. I've looked through the Marshal methods, but not found any that look like they can help.
I've added the attributes of COMInterface.IUnknown, and also the GUID number, to the interface, but i'm uncertain as to where to go from here.
Any help appreciated
Cheers
Cata
EDIT: Solved this one, see problem 2
|
|
|
|
|
Was using an In where i should have been using an Out.
My bad.
Next problem: Now I have an IntPtr to an interface, how do I marshal it to the interface I have constructed? I'm currently looking at: GetObjectForIUnknown, but i don't think that is what I'm looking for.
I get the impression from what I have read so far that I need to construct some kind of COM object and tie the interface too it, but I don't know what object IShellFolder is attatched to, and it's not in the documentation. Or I could be way off the mark.
As always, help appreciated.
Cata
|
|
|
|
|
You want Marshal.GetTypedObjectForIUnknown , for which you provide a Type parameter. Just look at all the methods on the Marshal class so you have some idea of what's there.
Since you've posted so many questions about COM with .NET, you really should read a book if you're having trouble understanding this. As I mentioned before, having a COM background helps. If you don't, try this: COM and .NET Component Services[^] from O'Reilly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath,
I'm getting there using the Help File. Here was the line of code I've strugging to figure out what to do with. (It's nice to know I was on the right track as well)
<br />
thing = new IntPtr();<br />
COMStuff.SHGetDesktopFolder(out thing);<br />
<br />
object Folder = Marshal.GetTypedObjectForIUnknown(thing, COMStuff.IShellFolder);<br />
To be honest, I'm not entirely sure what I am trying to achieve with this method. I mean, I get a pointer to an interface, and then I'd like to use the interface.
But i'm missing a milestoned somewhere along that path, and I don't know what it is. I need an object? Of what Type?
Cata
|
|
|
|
|
Instead of
object Folder = Marshal.GetTypedObjectForIUnknown(thing, COMStuff.IShellFolder); use
COMStuff.IShellFolder folder = (COMStuff.ISHellFolder)
Marshal.GetTypedObjectForIUnknown(thing, typeof(COMStuff.IShellFolder)); Also, instead of using out IntPtr as the param type to SHGetDesktopFolder that you seemed to have defined yourself, just use IShellFolder as the param (no out or ref ) and it should work just fine. Marshaling done by the CLR will take care of most of this.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks mate, figured it out on my own just as you posted
I'm just going through the Platform SDK documentation and converting anything I come across to C# COM. No particular purpose really, just learning about it. Very interesting, and i'm getting to grips with it quite nicely bar this small hickup.
Thanks
Cata
|
|
|
|
|
I'm using a load of flag values i've found in one of the Shell32 header files, however, when I try and compile it I get the error:
Cannot implicitly convery int to Uint.
This is for the two values:
SFGAO_HASSUBFOLDER = 0x80000000, // may contain children with SFGAO_FOLDER
SFGAO_CONTENTSMASK = 0x80000000,
I guess it's because the number is too large, but what can I do about it?
Cheers
Cata
|
|
|
|
|