How to convert .shp file into an array? - c#

I am using EasyGis.net to load a shape file in my desktop application.
I want to save this file in database so that i can use this file from the server side of my software.
I am able to save normal .png files in database by converting image object into a byte array.
Now i need to save the shape file so that i can use this from my server.

You can use this function:
File.ReadAllBytes(fileName);
Ref: https://msdn.microsoft.com/en-us/library/system.io.file.readallbytes(v=vs.110).aspx

Related

Copy byte array into clipboard

I'm trying to do a client-server program in which it is possible to share the content of the clipboard.
Right now I am able to share it if the content type is audio, image or text.
The idea is that I convert the content in a byte array, send it, convert it back in its original type (Stream, BitmapSource or string) and inject it in the client clipboard by using the methods Clipboard.SetAudio, Clipboard.SetImage or Clipboard.SetText.
My problem is when there are some files in the clipboard. I use the method Clipboard.GetFileDropList to get a list of the files, and for each file in the list I convert it in a byte array and send it to the client. How can I inject this byte array in the client clipboard?
I know there is the method Clipboard.SetFileDropList, but it requires me to provide a file list and since the file does not exist on the client I cannot use it.
How can I solve this problem?
In order to make the client treat the files as pastable, they'll need to exist on the client filesystem in some way, since the clipboard expects a list of filenames when setting clipboard content.
This can be done by transferring the data as a stream to your client, and then making the client immediately unpack that stream to a temp folder, the path to which is obtainable via:
var temp = Environment.ExpandEnvironmentVariables("%TEMP%");
Once done and the files are i place, you can position those files on the clipboard as if they were the ones copied.
Be warned that supporting file copy/paste instead of having an option to "transfer" files could run much slower than other operations, due to how big files can get.

Show PDF file from SQL Database

I already uploaded pdf files into my sql database as binary data file. I want to retrieve this file and open it with Adobe Reader on my form. But I couldn't solve it in C# code.
I want to retrieve the pdf file which id number = textbox1 and I want to load that file to axAcroPDF1 Adobe viewer.
I want to write this code to form load action.
textBox1.text= clipboard.gettext();
then retrieve code.
You first need to retrieve the data from the database in the same way as you would any other data. That will give you a Byte array. You can then call File.WriteAllBytes to write that data to a file. You can use the Path.GetTempFileName method to create a temp file to write the data to if appropriate. You can then use that path to open the file in your PDF reader as you normally would.

Embed image in file

I'm trying to figure out a way to embed an image into a file in c#.
What I'm doing is to create a file with text inside of it (it uses XML) , and I want a quite big image embedded into it which I then can read from the file along with the XML.
But how do I do that?
I can't put an image file along with the file since the file may be used on different computers and I don't want 100's of image files laying around with the files.
Any ideas would be appreciated!

Adding an image file to a database with C# and ASP.NET

How can I add an image file (for example, JPEG, PNG, GIF ...) to a database with C# and ASP.NET?
I'm just working on the project. And now I need your help.
The best way is to simply store the path of the image in the database. Answered fully here and here
If you want the actual image in the DB, then you will have to perform what is referred to as "Blobbing". You will need to convert the image into a Byte Array(Byte[]) and then store the array in the database. The field in the database is going to need to be appropriate for storing a Blob.
Then when you load the image from the DB (to display it), you will have to convert it back into an image. It would probably be useful to store the image type along with the image data so that you know what format to convert that image data into.
Try this
http://www.aspsnippets.com/Articles/Display-Images-in-GridView-Control-using-the-path-stored-in-SQL-Server-database.aspx

Display a file from a byte[] or stream

I've got a winforms app that stores the contents of files in a database. The stored files can be of just about any type (word, excel, PDF, text, image ...) the user can select just about any type of file to load.
The user can then query the database, find a file and then open it.
I've got no problems extracting the byte array from the database, as either a stream or a byte array.
Ideally I'd be able to display the file directly from a byte array or stream; at the moment I'm saving it as a temporary file and then opening that with:
Process.Start(fileName);
How can I display the file with the associated application either from any of the byte array or stream file?
In windows, your only option is to do exactly what you're doing. Outlook, Internet explorer, firefox, all do this
Maybe you want to research a little bit on Memory Mapped File.
you can try to open the directory containing it, but it will be the same thing you're doing right now.. if the associated app is known by the OS, then there will be no problem..
If you store a filename in the DB along with the byte stream, you can determine the file type from the extension. There's two options in this case:
Use the registry to determine what application to use. For more info on this, take a look at this conversation on bytes.com.
P/Invoke SHGetFileInfo to determine what application to use.
NB: With both options you'll still need to write the file data to a temp file on disk in order to load it.
Personally, I'd think what you're doing is probably the easiest option, anyway (unless you'd like to provide custom viewers for certain file-types, etc)

Categories

Resources