How to save Uploaded .pdf files to an sql database filed ? Please I Nedd Help It Very Urgent

I created insertdatafilelink.aspx to Insert an Uploaded .pdf files to a filed then when I run insertdatafilelink.aspx it inserts all data to all filed and Uploads

the .pdf files to the folder Documents put it doesn't save the .pdf files to the fied file_link. This is the code I used Please I want to know where I made the mistake.

1-This Is the insertdatafilelink.vb

Partial Class Insertdatatfilelink

Inherits System.Web.UI.Page

Protected Sub New_mail_system_ItemInserting(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs) _

Handles New_mail_system.ItemInserting

'Reference the FileUpload controls

Dim DocumentUpload As FileUpload = CType(New_mail_system.FindControl("DocumentUpload"), FileUpload)

If DocumentUpload.HasFile Then

'Make Sure That a PDF file has been uploaded

If String.Compare(System.IO.Path.GetExtension _

(DocumentUpload.FileName), ".pdf", True) <> 0 Then

uploadWarning.text = _

"only PDF documents May Used For A file link documents."

UploadWarning.visible = True

e.Cancel = True

Exit Sub

End If

Const DocumentDirectory As String = "~/Documents/"

Dim DocumentPath As String = DocumentDirectory & DocumentUpload.FileNameDim filenamewithoutextension As String = _

System.IO.Path.GetFileNameWithoutExtension(DocumentUpload.FileName)

Dim iteration As Integer = 1

While System.IO.File.Exists(Server.MapPath(DocumentPath))DocumentPath = String.Concat(DocumentDirectory, filenamewithoutextension, "-", iteration, ".pdf")

iteration += 1

End While

'Save The File To Disk And Set The Value Of The DocumentPath Parameter

DocumentUpload.SaveAs(Server.MapPath(DocumentPath))

e.Values(
"DocumentPath") = DocumentPath

End If

End Sub

Protected Sub New_mail_system_ItemInserted(ByVal sender As Object, ByVal e As DetailsViewInsertedEventArgs) _

Handles New_mail_system.ItemInserted

If e.Exception IsNot Nothing Then

'need delete document file, if it exists

If e.Values("DocumentPath") IsNot Nothing Then

System.IO.File.Delete(Server.MapPath(e.Values("DocumentPath").ToString()))

End If

End If

End Sub

End Class

 ---------------------------------------------------------------------------------------------------------------------

2- And this is the insertdatafilelink.aspx

<form id="form1" runat="server">

<div>

<asp:DetailsView ID="New_mail_system" runat="server" AutoGenerateRows="False" DataKeyNames="ID"

DataSourceID="insertdata" Height="50px" Width="249px" DefaultMode="Insert">

<Fields>

<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"

SortExpression="ID" />

<asp:BoundField DataField="entry_date" HeaderText="entry_date" SortExpression="entry_date" />

<asp:BoundField DataField="reference" HeaderText="reference" SortExpression="reference" />

<asp:BoundField DataField="type" HeaderText="type" SortExpression="type" />

<asp:BoundField DataField="subject" HeaderText="subject" SortExpression="subject" />

<asp:BoundField DataField="dest_from" HeaderText="dest_from" SortExpression="dest_from" />

<asp:BoundField DataField="dest_to" HeaderText="dest_to" SortExpression="dest_to" />

<asp:BoundField DataField="done_by" HeaderText="done_by" SortExpression="done_by" />

<asp:BoundField DataField="comments" HeaderText="comments" SortExpression="comments" />

<asp:TemplateField headertext="Document" SortExpression="file_link">

<InsertItemTemplate>

<asp:FileUpload id="DocumentUpload" runat="server" />

</InsertItemTemplate>

</asp:TemplateField>

 

<asp:CommandField ShowInsertButton="True" />

</Fields>

</asp:DetailsView>

<p>

<asp:Label ID="UploadWarning" runat="server" EnableViewState="false" Visible="false">

</asp:Label>

</p>

 

<asp:SqlDataSource ID="insertdata" runat="server" ConnectionString="<%$ ConnectionStrings:HSCCConnectionString2 %>"

DeleteCommand="DELETE FROM [hscc_mail_log] WHERE [ID] = @ID" InsertCommand="INSERT INTO [hscc_mail_log] ([entry_date], [reference], [type], [subject], [dest_from], [dest_to], [done_by], [comments], [file_link]) VALUES (@entry_date, @reference, @type, @subject, @dest_from, @dest_to, @done_by, @comments, @file_link)"

SelectCommand="SELECT * FROM [hscc_mail_log]" UpdateCommand="UPDATE [hscc_mail_log] SET [entry_date] = @entry_date, [reference] = @reference, [type] = @type, [subject] = @subject, [dest_from] = @dest_from, [dest_to] = @dest_to, [done_by] = @done_by, [comments] = @comments, [file_link] = @file_link WHERE [ID] = @ID">

<DeleteParameters>

<asp:Parameter Name="ID" Type="Int64" />

</DeleteParameters>

<UpdateParameters>

<asp:Parameter Name="entry_date" Type="DateTime" />

<asp:Parameter Name="reference" Type="String" />

<asp:Parameter Name="type" Type="String" />

<asp:Parameter Name="subject" Type="String" />

<asp:Parameter Name="dest_from" Type="String" />

<asp:Parameter Name="dest_to" Type="String" />

<asp:Parameter Name="done_by" Type="String" />

<asp:Parameter Name="comments" Type="String" />

<asp:Parameter Name="file_link" Type="String" />

<asp:Parameter Name="ID" Type="Int64" />

</UpdateParameters>

<InsertParameters>

<asp:Parameter Name="entry_date" Type="DateTime" />

<asp:Parameter Name="reference" Type="String" />

<asp:Parameter Name="type" Type="String" />

<asp:Parameter Name="subject" Type="String" />

<asp:Parameter Name="dest_from" Type="String" />

<asp:Parameter Name="dest_to" Type="String" />

<asp:Parameter Name="done_by" Type="String" />

<asp:Parameter Name="comments" Type="String" />

<asp:Parameter Name="file_link" Type="String" />

</InsertParameters>

</asp:SqlDataSource>

&nbsp;<br />

 

</div>

</form>

</body>

</html>

0
Mona111
8/13/2007 9:58:21 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

2 Replies
1394 Views

Similar Articles

[PageSpeed] 32
Get it on Google Play
Get it on Apple App Store

Since your directory location is a constant (Const DocumentDirectory As String = "~/Documents/") I would save the fileName to your DB.

DIM fileName AS string = FileUpload.FileName


If everything happens for a reason what is the reason for this error?
0
mpaterson
8/13/2007 7:39:31 PM

Hi,

This may helpful to you,

http://www.beansoftware.com/ASP.NET-Tutorials/Binary-Files-To-Database.aspx 


Mehedi Hasan


Mark as answer if the post meets your requirement!
0
M
8/14/2007 5:23:38 AM
Reply:

Similar Artilces:

File Upload to server and save path to uploaded file into a sql database
   I am trying to upload a file to a server and save the path of the uploaded file to a sql 2005 server. I have some code below but im getting the error Object reference not set to an instance of an object. Any help would be greatful. By the way I got this code from these forums and just tweaked them for my website. 1 Dim Fileupload1 As FileUpload = CType(FindControl("FileUpload1"), FileUpload) 2 Dim filePath1 As Label = CType(FindControl("filePath1"), Label) 3 4 If Fileupload1.HasFile Then 5 Try 6 Fileupload1...

file uploader save file on server and in database and upload this file on client
hi,i have a file uploader control user can attach files (.rar, .zip, etc) and store file folder and path in database. and another user can click of attach link and can download that file. how can i do this please solve out this problem. you can find your problem solution in this link and you can store the file name in your database server.http://www.aspnettutorials.com/tutorials/network/net-fileupload-aspnet2-csharp.aspxPlease Mark as Answred If This Blog has Helped You.RegardsMitesh Darjihttp://www.indianic.comhttp://www.mitatdotnet.blogspot.com As always there are many ways and which ...

Upload csv file to SQL Database, please help!
I would like to upload 3 csv files in a folder In all of the files, some of fields must be converted before storing to databse for example: csv File(String Format)    =>  Database (Date Format) '03-12-2004'                    => 3/12/2004 In the database there has been created 3 tables respectively and contain uploaded data. Therefore, before I insert a new record into the table, I need to check if there has existed. If the record has existed, then compare...

when saving a file (save page as) please have option of saving file the title and not the actual file name
Name: Dan Kelleher Product: Firefox Summary: when saving a file (save page as) please have option of saving file the title and not the actual file name Comments: I like you browser better than windows explorer but windows has one feature that I wish you had. When saving a file (save page as) please have option of saving file the title and not the actual file name. Many files have number names that have no relationship to the web page. Saving as the page title gives an exact indication of the topic of the page saved. Keep up the good work. see http://www.sciencedaily.com/news/...

Please help me to read .msg file from c#.net (urgent)and get to, subject cc, bcc property
hai,i have one folder called BTCCEmailQueue where i have <1000 .msg outlookfile and i have to read it one by one  and extract To,subject,bcc,cc ofthat particular one .how can i perform this task.byfijo______________________________________________This is the way i had created and saved .msg file//method which i use to save as .msg file   private void button1_Click(object sender, EventArgs e)        {            OMsg =(Microsoft.Office.Interop.Outlook._MailItem)OO.CreateItem(OlItemType....

Integrating do I integrate all help files
How do I integrate PFC, sybase and powerbuilderhelp files together help such that I can get help on all issues (PFC, sybase and powerbuilderhelp ) through powerbuilder's help-content menu only . Please don't cross-post. On 1 Nov 2004 12:34:08 -0700, "Damola adesuyi" <someone@microsoft.com> wrote: >How do I integrate PFC, sybase and powerbuilderhelp files together help such >that I can get help on all issues (PFC, sybase and powerbuilderhelp ) >through powerbuilder's help-content menu only . > Bruce Armstrong [TeamSybase] http://www....

Save a file to remote server with out the help of file uploader
Hi All,               here i want to save a file to remote server where my file will be in client system...here i don't want to use file uploader control.........In my application we have one function which will save word document to client systems temperory folder and that document again I want to save to server.........  Merry Christmas.............to You All........... Krishna. Could you transfer it via ftp to the folder? I assume you mean that you want the file saved automatically, rather than the user having to u...

Adding file information to SQL database on file upload
Hi there :) I'm in the final stage of my asp.net project and one of the last things I need to do is add the following file information to my SQL server 2000 database when a file is uploaded: First of all I have a resource table to which I need to add: - filename - file_path - file_size (the resource_id has a auto increment value) so that should hopefully be straight forward when the file is uploaded. The next step is to reference the new resource_id in my module_resource table. My module resource table consists of: - resource_id (foreign key) - module_id (foreign k...

How to save pdf files to SQL database?
Hi all, Can someone please brief me on how to save 'pdf' files(there are about 15 files) into a SQL database and retrieve/open it from a datagrid? I have about 15 pdf files on my webserver and need to save it in the SQL database, so every pdf file saved in the database will have a primary key and the file will be saved either as 'ntext' or 'binary' type...I just have this rough idea. If someone has a ready code in VB.net then nothing better( i know thats a shortcut :) but it will help me like a tutorial. C# code will do too, I can then convert the code to Vb.net Thanks a ton.Aartee...we ...

save file as .csv file..(Urgent ,urgent)
Can any body tell me can we save the file as .csv... that is i have the reulsts data in data table.   Please if any body having the code to export data from datatable to CSV... Kindly send me.. like Userid    Message   comments  firtname  lastnemt sss        djkdfdfd       dkfdfkd     Raj         kumar xxx       dkdjfdkd       kdkdkdk   raj &n...

File Upload
Hey I've got a fileUpload control on an aspx page that works fine for the accepted file type, .rpts, and brings up the correct error message for not allowed extensions such as .exes and .jpgs. But .pdf files should cause an error message to be displayed, as only .rpt files are allowed to be uploaded, but instead it brings up a blank page like a web500 page. Is there a known bug when attempting to upload pdf's?   Just in case,here's the only relevant code attached to the control:   If uploadFilename.EndsWith(".rpt") = True Then 'ensures only .rp...

Save a file on the server...using file upload..(Urgent plz)
Hi frinds I am using asp.net fileupload control to uplaod the file from My system.. and store that file on the server disk.. that is on one folder.. can any one tell me what are the things I need to have to stroe my uploaded file on the server.. like server path? servername?.. and can anyone give me a code that to map serverpath..my code is now.. /* fileSaveAsName */ //FileUpload1.SaveAs("C:\\uploads\\" + fileSaveAs); FileUpload1.SaveAs(fileSaveAs); this is here I am stroing in local system in c drive..   Thanks You need Server.MapPath(string path);FileUpload1....

Upload files using an IFRAME and save the name of the file to a database
Hello guys, I have a form that saves some data to a table. One of that field is a filename. I am using an iframe with a fileupload control to put the file on the server but I don't know how to pass the name of the file to the container form to save it to my database.  Any ideas? Thanks a lot. David If the IFrame is in the form itself then why cant you directly use the file upload control in the form ?? If you want to learn file uploading you can check it here http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/standard/fileupload.aspxNo question is so difficult...

upload multi files, then attach file, then delete files help
Hi, I have a web form that needs do three things in one time when user click "submit" button. 1. upload multi files into web server (In know how to do this part) 2. send a email with these uploaded file to another user. 3. delete these uploaded files from web server. I know how to do 1). But, do not know 2) and 3). I know how to send email without attachment, But, once I add attachments. it does not work. Please help. Many thanks. Xiuxain Hi there, Please check the following links.. Sending Attachments and to delete file .. imports sys...

Web resources about - How to save Uploaded .pdf files to an sql database filed ? Please I Nedd Help It Very Urgent - asp.net.getting-started

Help:Files - Wikipedia, the free encyclopedia
... the first step in using an image or other media file is to upload it to Wikimedia Commons , but for legal reasons, some files must be uploaded ...

Facebook Explains Auto-Enhancing of Photos Uploaded via iOS App
Facebook indirectly confirmed Tuesday’s report on auto-enhancing photos uploaded via its iOS application with a post on its engineering blog ...

Facebook Crosses 10 Billion Uploaded Photos
The Facebook Engineering team has just announced that Facebook users uploaded their 10 billionth photo to the site yesterday. Facebook is now ...

How many photos are uploaded to Facebook each day?
Answer (1 of 2): We currently have over 200 million photos uploaded per day, or around 6 billion per month. There are currently almost 90 billion ...

Gridplay - The Vine & IG Music Video Maker, Uploaded from Your Camera Roll on the App Store on iTunes ...
Get Gridplay - The Vine & IG Music Video Maker, Uploaded from Your Camera Roll on the App Store. See screenshots and ratings, and read customer ...


Happy Iranians - Original uploaded Iran version of Pharrell Williams " Happy " video - YouTube
Join me at https://www.facebook.com/Sufinumeerpage Young Iranians Arrested For Dancing In 'Happy' Pharrell Video Age: 25, Crime: Happiness About ...

#MyDubai: half a million images uploaded in four months
The number of hits over such a short period of time show how the project has sparked UAE residents’ imaginations, the state news agency Wam reported. ...

Throwback of the Day: Watch the First Video Ever Uploaded to YouTube
This 18-second clip titled “Me at the Zoo” is the very first video ever uploaded to the site 10 years ago today (April 23, 2005). And while it ...

A million minutes of history uploaded online
The AP and British Movietone will upload more than a million minutes of historical footage to YouTube.

Resources last updated: 12/14/2015 6:57:49 AM