Showing posts with label upload. Show all posts
Showing posts with label upload. Show all posts

Friday, March 23, 2012

FileUpload control and SQL Server 2005.

Hello,

I have a FileUpload control on my webform. I would like a user to be able to upload a file to the server. Is there any way to store this file in SQL Server 2005?

Thanks

ASPSQL66

Here is a piece of code from one of my projects.
DataTable reqTable =new DataTable ("Request");SqlDataAdapter dataAdapter =new SqlDataAdapter ("Select * FROM Request", sqlconn);DataRow dataCurrentRow =null;SqlCommandBuilder builder =new SqlCommandBuilder (dataAdapter);builder.QuotePrefix ="[";builder.QuoteSuffix ="]";dataAdapter.Fill (reqTable);foreach (DataRow dataRowin reqTable.Rows){if ((long) dataRow["ID"] == requestID){dataCurrentRow = dataRow;break;}}dataCurrentRow["Attachment"] = fuAttachment.FileBytes;dataAdapter.Update (reqTable);

The above code updates the [Attachment] VARBINARY(MAX) field of the [Request] table where theID of the row matchesrequestID variable's value.fuAttachment is the FileUpload control on the page. I ripped off the exception handling and other error checking code.

Hope this helps

Wednesday, March 21, 2012

Files in SQL 2005

Hello,
In my ASP.NET 2.0 web site I need to upload many files to various
folders and add the information in an SQL 2005 database.
I am creating a documents table which includes the fields:
[DocumentId], [DocumentAuthor] and [DocumentUrl]
This table will have records for many files.
Is there a standard way to name the files?
Maybe renaming the files to "doc" + DocumentId?
However my DocumentId is a Guid so it would be to big ... I think.
I would need to create the record, get the DocumentId and then access
the record again to add the DocumentUrl after renaming the file in
my .NET code.
Anyway, is there a standard way to make sure that every file name is
unique and that at the same time won't have an unreadable name?
Thanks,
Miguel
On Feb 14, 4:05 pm, "shapper" <mdmo...@.gmail.com> wrote:
> Hello,
> In my ASP.NET 2.0 web site I need to upload many files to various
> folders and add the information in an SQL 2005 database.
> I am creating a documents table which includes the fields:
> [DocumentId], [DocumentAuthor] and [DocumentUrl]
> This table will have records for many files.
> Is there a standard way to name the files?
> Maybe renaming the files to "doc" + DocumentId?
> However my DocumentId is a Guid so it would be to big ... I think.
> I would need to create the record, get the DocumentId and then access
> the record again to add the DocumentUrl after renaming the file in
> my .NET code.
> Anyway, is there a standard way to make sure that every file name is
> unique and that at the same time won't have an unreadable name?
> Thanks,
> Miguel
one possible solution make DocumentId as identity and store document
as documentid value
sql

Files in SQL 2005

Hello,
In my ASP.NET 2.0 web site I need to upload many files to various
folders and add the information in an SQL 2005 database.
I am creating a documents table which includes the fields:
[DocumentId], [DocumentAuthor] and [DocumentUrl]
This table will have records for many files.
Is there a standard way to name the files?
Maybe renaming the files to "doc" + DocumentId?
However my DocumentId is a Guid so it would be to big ... I think.
I would need to create the record, get the DocumentId and then access
the record again to add the DocumentUrl after renaming the file in
my .NET code.
Anyway, is there a standard way to make sure that every file name is
unique and that at the same time won't have an unreadable name?
Thanks,
MiguelOn Feb 14, 4:05 pm, "shapper" <mdmo...@.gmail.com> wrote:
> Hello,
> In my ASP.NET 2.0 web site I need to upload many files to various
> folders and add the information in an SQL 2005 database.
> I am creating a documents table which includes the fields:
> [DocumentId], [DocumentAuthor] and [DocumentUrl]
> This table will have records for many files.
> Is there a standard way to name the files?
> Maybe renaming the files to "doc" + DocumentId?
> However my DocumentId is a Guid so it would be to big ... I think.
> I would need to create the record, get the DocumentId and then access
> the record again to add the DocumentUrl after renaming the file in
> my .NET code.
> Anyway, is there a standard way to make sure that every file name is
> unique and that at the same time won't have an unreadable name?
> Thanks,
> Miguel
one possible solution make DocumentId as identity and store document
as documentid value

Files in SQL 2005

Hello,
In my ASP.NET 2.0 web site I need to upload many files to various
folders and add the information in an SQL 2005 database.
I am creating a documents table which includes the fields:
[DocumentId], [DocumentAuthor] and [DocumentUrl]
This table will have records for many files.
Is there a standard way to name the files?
Maybe renaming the files to "doc" + DocumentId?
However my DocumentId is a Guid so it would be to big ... I think.
I would need to create the record, get the DocumentId and then access
the record again to add the DocumentUrl after renaming the file in
my .NET code.
Anyway, is there a standard way to make sure that every file name is
unique and that at the same time won't have an unreadable name?
Thanks,
MiguelOn Feb 14, 4:05 pm, "shapper" <mdmo...@.gmail.com> wrote:
> Hello,
> In my ASP.NET 2.0 web site I need to upload many files to various
> folders and add the information in an SQL 2005 database.
> I am creating a documents table which includes the fields:
> [DocumentId], [DocumentAuthor] and [DocumentUrl]
> This table will have records for many files.
> Is there a standard way to name the files?
> Maybe renaming the files to "doc" + DocumentId?
> However my DocumentId is a Guid so it would be to big ... I think.
> I would need to create the record, get the DocumentId and then access
> the record again to add the DocumentUrl after renaming the file in
> my .NET code.
> Anyway, is there a standard way to make sure that every file name is
> unique and that at the same time won't have an unreadable name?
> Thanks,
> Miguel
one possible solution make DocumentId as identity and store document
as documentid value

Friday, March 9, 2012

File Upload to SQL in 2.0 VB

Can anyone give me an example of how to Upload a file to SQL in asp.net 2.0 using VB?

Thanks

Randy

The way i do it is with a table of 3 columns:

ImgSize(int)
ImgContentType(nvarchar)
ImgFile(image)

Code:

'Pic is a File Upload Contol

Dim cnn As New SqlConnection(strConn)

Dim imgStream As Stream = Pic.PostedFile.InputStream
Dim imgLen As Integer = Pic.PostedFile.ContentLength
Dim imgContentType As String = Pic.PostedFile.ContentType

Dim imgBinaryData As Byte() = New Byte(imgLen) {}
Dim n As Integer = imgStream.Read(imgBinaryData, 0, imgLen)

You then build your command object and set your parameters with
the value you got above (imgStream, imgLen, imgContentType) and
then execute an non query.

Let me know if you need help reading as well !


|||@.amensi: ei that's the same problem as mine! So that's it, but if you don't me asking, can that also upload a MS word text file? if it doesn't can you please post the source code and where to put it? thanks!

File Upload Help

Hi, I am trying to upload a file to database.

I have used the following code, every loads good to the database apart from the image, does it go anywhere?

I have created a column in the table called 'FileUploadAdvert' and made it an image?

Any ideas where I'm going wrong?

Thanks

Gordon

ProtectedSub btnAdvertSubmit_Click(ByVal senderAsObject,ByVal eAs System.EventArgs)Handles btnAdvertSubmit.Click

Dim dashDataSourceAsNew SqlDataSource()dashDataSource.ConnectionString = ConfigurationManager.ConnectionStrings("DashConnectionString1").ToString()

dashDataSource.InsertCommandType = SqlDataSourceCommandType.Text

dashDataSource.InsertCommand ="INSERT INTO tblAdvert (AdvertOwner, AdvertName, TopLeftH, TopLeftV, Height, Width, ToolTip, WebLink, AcceptTerms, DateTimeStamp, IPAddress) VALUES (@.AdvertOwner, @.AdvertName, @.TopLeftH, @.TopLeftV, @.Height, @.Width, @.ToolTip, @.WebLink, @.AcceptTerms, @.DateTimeStamp, @.IPAddress)"

dashDataSource.InsertParameters.Add("AdvertOwner", txtName.Text)

dashDataSource.InsertParameters.Add("AdvertName", txtCompName.Text)

dashDataSource.InsertParameters.Add("TopLeftH", DropDownAccross.Text)

dashDataSource.InsertParameters.Add("TopLeftV", DropDownDown.Text)

dashDataSource.InsertParameters.Add("Height", DropDownHeight.Text)

dashDataSource.InsertParameters.Add("Width", DropDownWidth.Text)

dashDataSource.InsertParameters.Add("ToolTip", txtOver.Text)

dashDataSource.InsertParameters.Add("Weblink", txtURL.Text)

dashDataSource.InsertParameters.Add("AcceptTerms", CheckBoxAgree.Checked)

dashDataSource.InsertParameters.Add("IPAddress", Request.UserHostAddress.ToString)

dashDataSource.InsertParameters.Add("DateTimeStamp", DateTime.Now)

IfNot FileUploadAdvert.PostedFileIsNothingThen

Dim filepathAsString = FileUploadAdvert.PostedFile.FileName

Dim patAsString ="\\(?:.+)\\(.+)\.(.+)"

Dim rAs Regex =New Regex(pat)

'run

Dim mAs Match = r.Match(filepath)

Dim file_extAsString = m.Groups(2).Captures(0).ToString()

Dim filenameAsString = m.Groups(1).Captures(0).ToString()

Dim fileAsString = filename &"." & file_ext

'save the file to the server

FileUploadAdvert.PostedFile.SaveAs(Server.MapPath(".\") & file)

lblStatus.Text ="File Saved to: " & Server.MapPath(".\") & file

EndIf

Dim rowsAffectedAsInteger = 0

Try

rowsAffected = dashDataSource.Insert()

Catch exAs Exception

Server.Transfer("Register_Fail.aspx")

Finally

dashDataSource =Nothing

EndTry

If rowsAffected <> 1Then

Server.Transfer("Register_Fail.aspx")

Else

Server.Transfer("Register_Complete.aspx")

EndIf

EndSub

Looking at your code, all you have done is saved the uploaded file onto theweb server's file system.

You have not saved it into the database.

Ifyou want to save the actual image to your database you will need to geta byte array from the image, then update your insert statement toinclude the image and pass in the byte array as a binary type inputparameter.

Or the other way is just to store the file path of where you saved the image on your file system to your database.

|||

Any Idea how I do either of those? I've hit a bit of a dead end!

Sunday, February 26, 2012

File Size Limitation

Hi,
I'm trying to upload word documet to report server. I got an error message
that maximum size exceeded. Can anyone tell what's the limitation of size of
the file to be uploaded?
--
Thanks,
IDYou may want to check this related thread:
http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.sqlserver.reportingsvcs&mid=74513284-1467-4a32-b711-bdd7598292e0&sloc=en-us
-- Robert
This posting is provided "AS IS" with no warranties, and confers no rights.
"exkievan" <exkievan@.discussions.microsoft.com> wrote in message
news:5E3FA1CA-1C7D-45AB-9F3D-668D26899239@.microsoft.com...
> Hi,
> I'm trying to upload word documet to report server. I got an error message
> that maximum size exceeded. Can anyone tell what's the limitation of size
> of
> the file to be uploaded?
> --
> Thanks,
> ID|||Thanks
"Robert Bruckner [MSFT]" wrote:
> You may want to check this related thread:
> http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.sqlserver.reportingsvcs&mid=74513284-1467-4a32-b711-bdd7598292e0&sloc=en-us
>
> -- Robert
> This posting is provided "AS IS" with no warranties, and confers no rights.
> "exkievan" <exkievan@.discussions.microsoft.com> wrote in message
> news:5E3FA1CA-1C7D-45AB-9F3D-668D26899239@.microsoft.com...
> > Hi,
> >
> > I'm trying to upload word documet to report server. I got an error message
> > that maximum size exceeded. Can anyone tell what's the limitation of size
> > of
> > the file to be uploaded?
> > --
> > Thanks,
> >
> > ID
>
>