For Programmers: Free Programming Magazines  


Home > Archive > ASP .NET > February 2007 > Uploading file from Database









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Uploading file from Database
tshad

2007-02-27, 7:13 pm

I have a file that I want to upload periodically from a users machine if
they come back later.

I am storing the filename and path in my database. But the HtmlInputFile
normally file is set to read-only.

For example, if I have the object:

<input id="MyResumeFile" style="width:300px" type="File" runat="Server">

If I get the filename from an earlier upload that I stored in my database as
such:

MyResumeFile.PostedFile.FileName = dbReader("UploadFileName")

I get the error:

Property 'FileName' is 'ReadOnly'

Is there a way to use the name stored in a database with the Upload File
object?

Thanks,

Tom


Alexey Smirnov

2007-02-28, 4:13 am

On Feb 28, 1:22 am, "tshad" <t...@home.com> wrote:
> I have a file that I want to upload periodically from a users machine if
> they come back later.
>
> I am storing the filename and path in my database. But the HtmlInputFile
> normally file is set to read-only.
>
> For example, if I have the object:
>
> <input id="MyResumeFile" style="width:300px" type="File" runat="Server">
>
> If I get the filename from an earlier upload that I stored in my database as
> such:
>
> MyResumeFile.PostedFile.FileName = dbReader("UploadFileName")
>
> I get the error:
>
> Property 'FileName' is 'ReadOnly'
>
> Is there a way to use the name stored in a database with the Upload File
> object?
>
> Thanks,
>
> Tom


it's true - FileName is ReadOnly because it give your the source name

Use PostedFile.SaveAs to save the file with desired name

For example,

NewFileName = Server.MapPath("/resume/") & dbReader("UploadFileName")
MyResumeFile.PostedFile.SaveAs(NewFileName)

Mark Rae

2007-02-28, 4:13 am

"tshad" <t@home.com> wrote in message
news:uLZCb6sWHHA.4216@TK2MSFTNGP02.phx.gbl...

> MyResumeFile.PostedFile.FileName = dbReader("UploadFileName")
>
> I get the error:
>
> Property 'FileName' is 'ReadOnly'


That's right.

> Is there a way to use the name stored in a database with the Upload File
> object?


No, for (fairly obvious!) security reasons. Imagine the following on a
public website:

MyResumeFile.PostedFile.FileName = @"C:\...\...\Outlook.pst";


tshad

2007-02-28, 10:07 pm

Makes sense.

Thanks,

Tom
"Mark Rae" <mark@markNOSPAMrae.com> wrote in message
news:OSRE%237xWHHA.3592@TK2MSFTNGP03.phx.gbl...
> "tshad" <t@home.com> wrote in message
> news:uLZCb6sWHHA.4216@TK2MSFTNGP02.phx.gbl...
>
>
> That's right.
>
>
> No, for (fairly obvious!) security reasons. Imagine the following on a
> public website:
>
> MyResumeFile.PostedFile.FileName = @"C:\...\...\Outlook.pst";
>



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com