Reply

Can I return a file after I have extracted it?

[ Edited ]

Hi all

 

I am a programmer working with a Solid Edge client who wants to programmically change a custom property on a draft file.

 

As pointed out in your article on Database file extraction:

"SharePoint 2003 stores files in the Docs table in a field named Content. "

 

While we have found the custom tag in the MetaInfo column and successfully changed it directly in MS SQL, we did not change it in the draft file stored in the Content column.

 

Your article on Database file extraction shows how to extract the file, the product "Newell.SolidEdgeFileProperties" states: "With this API, you can read and write Solid Edge File Properties".

 

So if I extract the 2d file, change the value of a custom tag, all I have left is to import the file back into MS SQL.

 

Is there a way to bring the modified file back into MS SQL (the Contents column of the Docs table)?

 

Thanks in advance

 

Graig Smith

 

Posted by: Graig Smith
Post date: 7/18/2006 12:07:44 PM

1 REPLY

RE: Can I return a file after I have extracted it?

[ Edited ]

Graig,

 

Hello and thanks for registering.

 

I have a sign at my desk with the quote "Calm down, it's only zeros and ones!". A binary file is nothing more than a byte array of some length.

 

Looking at my article code, "I haven't look at it in over a year ", I see that I'm using:

 

Dim content() As Byte

content = objCommand.ExecuteScalar()

 

Then:

 

objFS.Write(content, 0, content.Length)

 

Ok, so basically we need to reverse this process to get the file back into SQL.

 

Simple google search turns up http://www.wwwcoder.com/main/parentid/191/site/5528/68/default.aspx.

 

 

// create a byte[] for the image file that is uploaded

int imagelen = Upload.PostedFile.ContentLength;

byte[] picbyte = new byte[imagelen];

Upload.PostedFile.InputStream.Read (picbyte, 0, imagelen);

// Insert the image and image id into the database

SqlConnection conn = new SqlConnection (@"give the connection string here...");

try

{

conn.Open ();

SqlCommand cmd = new SqlCommand ("insert into ImageTable " + "(ImageField, ImageID) values (@pic, @imageid)", conn);

cmd.Parameters.Add ("@pic", picbyte);

cmd.Parameters.Add ("@imageid", lblImageID.Text);

cmd.ExecuteNonQuery ();

}

finally

{

conn.Close ();

}

 

 

So the jist is that we want to read the binary file into a byte array variable and stuff it into a CommandParameter. Now I don't have everything I need to code this up for you but here's a little.

 

 

Imports System.IO

 

Module Module1

 

Sub Main()

Dim objFS As FileStream

objFS = File.OpenRead("C:\Asm1-1.asm")

Dim content(objFS.Length) As Byte

objFS.Read(content, 0, objFS.Length)

 

' Write Update SQL statement using content variable.

End Sub

 

End Module

 

 

I do not currently have access to an Insight or SQL or I would help you more. Hopefully this will be enough to get you going. If not, feel free to reply back and I'll do whatever I can.

 

Good luck!

 

Posted by: Jason Newell
Post date: 7/18/2006 1:32:57 PM