reading pdf files from a folder and place it in the sql server dat

G

Guest

Hi,

I need to read a pdf file which is on my hard drive and put it in the sql
server database. Once placed in the sql server, I again need to read that
file from the database and display it on the web? Is it possible? Could you
please provide some links where I could find the information?

Thanks,
Sridhar.
 
N

n33470

Sridhar,

Look at the SQLServer datatype 'Image". You create a table with
column of type 'Image'. Then create stored procs to get/set the
Image datatype. On the .NET side, the byte[] can be used to plug into
the Image parameter to the stored procs. Here is a small example of
the call to the stored proc that will save the file into the table.

public bool UploadFile(User user, int formId, byte[] fileContents)
{

SqlParameter[] parameters =
{
new SqlParameter("@FormId", SqlDbType.Int), // 1
new SqlParameter("@FileContents", SqlDbType.Image), // 2
};

// Set parameter values and directions
parameters[0].Value = formId;
parameters[1].Value = fileContents;

// Run the stored procedure
this.RunPersistSP("spJJK_RSMScanForm__UploadNestorZDF", parameters);

}



--steve
 
G

Guest

Hi,

I found a link to do that. But I am having some problems. Here is the
code I am using to read the pdf file from a folder. It is doing PostBack
twice. I am not sure why it is doing that. If you have any idea please let me
know

Private Sub ReadPdfFile(ByVal strFilepath As String)
'Create WebClient Object
Dim objWebClient As New WebClient
'Create Byte Array to download data
Dim byteBuffer() As Byte = objWebClient.DownloadData(strFilepath)

'Read Data
If Not byteBuffer Is Nothing Then
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", byteBuffer.Length.ToString())
Response.BinaryWrite(byteBuffer)
End If
End Sub

I am thinking it might be due to Response.BinaryWrite(). Is there any
solution to this?

Thanks,
Sridhar.
 
N

n33470

Sridhar,

Try this block of code to send the file to the browser:

Response.ClearContent();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", byteBuffer.Length.ToString())

Response.BinaryWrite(byteBuffer);
Response.Flush();
Response.Close();


Notice the call to clear the response stream first, this will remove
any other html that might already be on the stream. Next, the
Flush()/Close() is important so that it sends the data to the browser
and ends the processing of the page. I've personally never used
BinaryWrite(), but I would not think that would be your problem.

HTH,

--steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top