By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,558 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,558 IT Pros & Developers. It's quick & easy.

File Upload and CSS

P: n/a
I'm having a small problem with uploading files in ASP.NET.

My html page for uploading has something similar to:

<form id="Form1" method="post" enctype="multipart/form-data" runat="server">
<input id="MyFile" type="file" runat="server" size="50">
<asp:Button Runat="server" ID="btnUpload" Text="UPLOAD" />
</form>

.. . .and the corresponding vb.net code:

Dim strFullPath As String
strFullPath = MyFile.PostedFile.FileName
Dim strFileName As String
strFileName = Path.GetFileName(strFullPath)
'ViewState("strDirectory") might by a folder like "db/" or "pdf/"
MyFile.PostedFile.SaveAs(ViewState("strDirectory") & strFileName)

All very straighforward stuff that we've all used before.

A file will upload just fine with the above code. The problem is, that when
the page comes back to the browser, all the CSS is lost. This is true in
both IE6 and FireFox 1.0. The design of the page(s) is a TableLess design
(no html tables). I have other projects where this worked fine, and the
CSS wasn't lost, but the upload was in an html table. Since it happens in
both of these browsers, I'm thinking it isn't browser dependent??

My question is: Is there something wrong with the above code that is triggering
the CSS to be lost? Is it a bug in ASP.NET?

As a solution, I could probably redirect the user to a different page indicating
the results of their attempted file upload.
Maybe I could try setting using:
Response.Cache.SetCacheability(HttpCacheability.No Cache)
at the top of the page?

I appreciate any advice y'all can give.

Thanks,

Todd Acheson

Nov 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
The "CSS is lost" ? Do you mean that tht resulting HTML code doesn't contain
any more a reference to your external sttylesheet ?

How is this stylesheet referenced from your APSX Page ?

Patrice


--

"Todd Acheson" <ta******@questared.com> a écrit dans le message de
news:13**********************@msnews.microsoft.com ...
I'm having a small problem with uploading files in ASP.NET.

My html page for uploading has something similar to:

<form id="Form1" method="post" enctype="multipart/form-data" runat="server"> <input id="MyFile" type="file" runat="server" size="50">
<asp:Button Runat="server" ID="btnUpload" Text="UPLOAD" />
</form>

. .and the corresponding vb.net code:

Dim strFullPath As String
strFullPath = MyFile.PostedFile.FileName
Dim strFileName As String
strFileName = Path.GetFileName(strFullPath)
'ViewState("strDirectory") might by a folder like "db/" or "pdf/"
MyFile.PostedFile.SaveAs(ViewState("strDirectory") & strFileName)

All very straighforward stuff that we've all used before.

A file will upload just fine with the above code. The problem is, that when the page comes back to the browser, all the CSS is lost. This is true in
both IE6 and FireFox 1.0. The design of the page(s) is a TableLess design
(no html tables). I have other projects where this worked fine, and the
CSS wasn't lost, but the upload was in an html table. Since it happens in
both of these browsers, I'm thinking it isn't browser dependent??

My question is: Is there something wrong with the above code that is triggering the CSS to be lost? Is it a bug in ASP.NET?

As a solution, I could probably redirect the user to a different page indicating the results of their attempted file upload.
Maybe I could try setting using:
Response.Cache.SetCacheability(HttpCacheability.No Cache)
at the top of the page?

I appreciate any advice y'all can give.

Thanks,

Todd Acheson

Nov 19 '05 #2

P: n/a
Oh, and another problem:

After the file is uploaded, if I have a link to this newly uploaded file,
and the user clicks on that link, they are prompted for WIndows Security
information (username, domain, and password).
But, if I publish that same file with FrontPage to the same directory that
it was uploaded, the user is longer prompted for security, and the link
works fine.

Any advice?

--
Todd Acheson

================================
"Todd Acheson" <ta******@questared.com> wrote in message
news:13**********************@msnews.microsoft.com ...
I'm having a small problem with uploading files in ASP.NET.

My html page for uploading has something similar to:

<form id="Form1" method="post" enctype="multipart/form-data" runat="server"> <input id="MyFile" type="file" runat="server" size="50">
<asp:Button Runat="server" ID="btnUpload" Text="UPLOAD" />
</form>

. .and the corresponding vb.net code:

Dim strFullPath As String
strFullPath = MyFile.PostedFile.FileName
Dim strFileName As String
strFileName = Path.GetFileName(strFullPath)
'ViewState("strDirectory") might by a folder like "db/" or "pdf/"
MyFile.PostedFile.SaveAs(ViewState("strDirectory") & strFileName)

All very straighforward stuff that we've all used before.

A file will upload just fine with the above code. The problem is, that when the page comes back to the browser, all the CSS is lost. This is true in
both IE6 and FireFox 1.0. The design of the page(s) is a TableLess design
(no html tables). I have other projects where this worked fine, and the
CSS wasn't lost, but the upload was in an html table. Since it happens in
both of these browsers, I'm thinking it isn't browser dependent??

My question is: Is there something wrong with the above code that is triggering the CSS to be lost? Is it a bug in ASP.NET?

As a solution, I could probably redirect the user to a different page indicating the results of their attempted file upload.
Maybe I could try setting using:
Response.Cache.SetCacheability(HttpCacheability.No Cache)
at the top of the page?

I appreciate any advice y'all can give.

Thanks,

Todd Acheson

Nov 19 '05 #3

P: n/a
Hello Patrice,

What I mean by "CSS is lost" is that the page has all the content for the
user, but the formatting supplied by the CSS is not being applied.

I reference the CSS by:

<link href="styles.css" type="text/css" rel="stylesheet">

which is in the head of the html document.

-Todd
The "CSS is lost" ? Do you mean that tht resulting HTML code doesn't
contain any more a reference to your external sttylesheet ?

How is this stylesheet referenced from your APSX Page ?

Patrice

Nov 19 '05 #4

P: n/a
When it occurs have a look at the "show source" option in the browser to see
if the html code you send is correct (in particular do you have all always
the link tag ?). Note also that it looks like you are searching the css file
in the same location than your aspx page (is this intended ? What if you
replace the name of the page in the address bar with styles.css ? Can you
get the file ?)

Patrice

--

"Todd Acheson" <ta******@questared.com> a écrit dans le message de
news:13**********************@msnews.microsoft.com ...
Hello Patrice,

What I mean by "CSS is lost" is that the page has all the content for the
user, but the formatting supplied by the CSS is not being applied.

I reference the CSS by:

<link href="styles.css" type="text/css" rel="stylesheet">

which is in the head of the html document.

-Todd
The "CSS is lost" ? Do you mean that tht resulting HTML code doesn't
contain any more a reference to your external sttylesheet ?

How is this stylesheet referenced from your APSX Page ?

Patrice


Nov 19 '05 #5

P: n/a
Patrice,

I can still get the CSS file by typing it in the address bar.

When I look at the source of the page (View Source) in IE, the html for the
CSS link is missing!

Well now I know why the CSS is not being applied. The question becomes,
why?
-Todd

--
Todd Acheson

"Patrice" <no****@nowhere.com> wrote in message
news:ej****************@TK2MSFTNGP12.phx.gbl...
When it occurs have a look at the "show source" option in the browser to see if the html code you send is correct (in particular do you have all always
the link tag ?). Note also that it looks like you are searching the css file in the same location than your aspx page (is this intended ? What if you
replace the name of the page in the address bar with styles.css ? Can you
get the file ?)

Patrice

--

"Todd Acheson" <ta******@questared.com> a écrit dans le message de
news:13**********************@msnews.microsoft.com ...
Hello Patrice,

What I mean by "CSS is lost" is that the page has all the content for the user, but the formatting supplied by the CSS is not being applied.

I reference the CSS by:

<link href="styles.css" type="text/css" rel="stylesheet">

which is in the head of the html document.

-Todd
The "CSS is lost" ? Do you mean that tht resulting HTML code doesn't
contain any more a reference to your external sttylesheet ?

How is this stylesheet referenced from your APSX Page ?

Patrice



Nov 19 '05 #6

P: n/a
I fixed the problem of losing my CSS reference. The tag for the link to the
stylesheet is in a user control. The code for making the tag was within a
If Not Page.IsPostBack block of code. Removing this If statement fixed the
problem.

I'm still wondering why the users are prompted for Windows security when
clicking on a link to user uploaded files? Files published with FrontPage
don't have this problem.

My web.config has the authentication set to "none".

Todd Acheson
--
Todd Acheson

"Todd A" <ze**@olympus.com> wrote in message
news:OG****************@TK2MSFTNGP09.phx.gbl...
Oh, and another problem:

After the file is uploaded, if I have a link to this newly uploaded file,
and the user clicks on that link, they are prompted for WIndows Security
information (username, domain, and password).
But, if I publish that same file with FrontPage to the same directory that
it was uploaded, the user is longer prompted for security, and the link
works fine.

Any advice?

--
Todd Acheson

================================
"Todd Acheson" <ta******@questared.com> wrote in message
news:13**********************@msnews.microsoft.com ...
I'm having a small problem with uploading files in ASP.NET.

My html page for uploading has something similar to:

<form id="Form1" method="post" enctype="multipart/form-data"

runat="server">
<input id="MyFile" type="file" runat="server" size="50">
<asp:Button Runat="server" ID="btnUpload" Text="UPLOAD" />
</form>

. .and the corresponding vb.net code:

Dim strFullPath As String
strFullPath = MyFile.PostedFile.FileName
Dim strFileName As String
strFileName = Path.GetFileName(strFullPath)
'ViewState("strDirectory") might by a folder like "db/" or "pdf/"
MyFile.PostedFile.SaveAs(ViewState("strDirectory") & strFileName)

All very straighforward stuff that we've all used before.

A file will upload just fine with the above code. The problem is, that

when
the page comes back to the browser, all the CSS is lost. This is true in both IE6 and FireFox 1.0. The design of the page(s) is a TableLess design (no html tables). I have other projects where this worked fine, and the
CSS wasn't lost, but the upload was in an html table. Since it happens in both of these browsers, I'm thinking it isn't browser dependent??

My question is: Is there something wrong with the above code that is

triggering
the CSS to be lost? Is it a bug in ASP.NET?

As a solution, I could probably redirect the user to a different page

indicating
the results of their attempted file upload.
Maybe I could try setting using:
Response.Cache.SetCacheability(HttpCacheability.No Cache)
at the top of the page?

I appreciate any advice y'all can give.

Thanks,

Todd Acheson


Nov 19 '05 #7

P: n/a
Check the permissions on the uploaded files and make sure read access is
allowed. I think the account that needs access is "IUSR_<machinename>" but I
might be wrong about that.

"Todd Acheson" wrote:
I fixed the problem of losing my CSS reference. The tag for the link to the
stylesheet is in a user control. The code for making the tag was within a
If Not Page.IsPostBack block of code. Removing this If statement fixed the
problem.

I'm still wondering why the users are prompted for Windows security when
clicking on a link to user uploaded files? Files published with FrontPage
don't have this problem.

My web.config has the authentication set to "none".

Todd Acheson
--
Todd Acheson

"Todd A" <ze**@olympus.com> wrote in message
news:OG****************@TK2MSFTNGP09.phx.gbl...
Oh, and another problem:

After the file is uploaded, if I have a link to this newly uploaded file,
and the user clicks on that link, they are prompted for WIndows Security
information (username, domain, and password).
But, if I publish that same file with FrontPage to the same directory that
it was uploaded, the user is longer prompted for security, and the link
works fine.

Any advice?

--
Todd Acheson

================================
"Todd Acheson" <ta******@questared.com> wrote in message
news:13**********************@msnews.microsoft.com ...
I'm having a small problem with uploading files in ASP.NET.

My html page for uploading has something similar to:

<form id="Form1" method="post" enctype="multipart/form-data"

runat="server">
<input id="MyFile" type="file" runat="server" size="50">
<asp:Button Runat="server" ID="btnUpload" Text="UPLOAD" />
</form>

. .and the corresponding vb.net code:

Dim strFullPath As String
strFullPath = MyFile.PostedFile.FileName
Dim strFileName As String
strFileName = Path.GetFileName(strFullPath)
'ViewState("strDirectory") might by a folder like "db/" or "pdf/"
MyFile.PostedFile.SaveAs(ViewState("strDirectory") & strFileName)

All very straighforward stuff that we've all used before.

A file will upload just fine with the above code. The problem is, that

when
the page comes back to the browser, all the CSS is lost. This is true in both IE6 and FireFox 1.0. The design of the page(s) is a TableLess design (no html tables). I have other projects where this worked fine, and the
CSS wasn't lost, but the upload was in an html table. Since it happens in both of these browsers, I'm thinking it isn't browser dependent??

My question is: Is there something wrong with the above code that is

triggering
the CSS to be lost? Is it a bug in ASP.NET?

As a solution, I could probably redirect the user to a different page

indicating
the results of their attempted file upload.
Maybe I could try setting using:
Response.Cache.SetCacheability(HttpCacheability.No Cache)
at the top of the page?

I appreciate any advice y'all can give.

Thanks,

Todd Acheson



Nov 19 '05 #8

P: n/a
BW
Todd,

When they click on the link, they're basicly downloading the file right? I
think what you have to do is get the browser to display the download box
instead of trying to open the file. I'm not sure of the correct term for it
but you basicly stream the attachment. Something like this:

the file link calls the FileDownload.aspx page like...: <a
href=FileDownload.aspx?file=yourFileWithFullPathAn dExtension>File Name</a>

<%@ Import Namespace="System.IO"%>
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)

Dim filepath As String = Request.Params("file")
If Not filepath Is Nothing Then
If File.Exists(filepath) Then
Dim filename As String = Path.GetFileName(filepath)
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & filename & """")
Response.Flush()
Response.WriteFile(filepath)
End If
End If

End Sub
</script>

This works fine for me. I hope this helps. re:
http://www.ondotnet.com/lpt/a/1354

Bernard

"Todd Acheson" <ta******@questared.com> wrote in message
news:ej****************@TK2MSFTNGP09.phx.gbl...
I fixed the problem of losing my CSS reference. The tag for the link to
the
stylesheet is in a user control. The code for making the tag was within a
If Not Page.IsPostBack block of code. Removing this If statement fixed
the
problem.

I'm still wondering why the users are prompted for Windows security when
clicking on a link to user uploaded files? Files published with FrontPage
don't have this problem.

My web.config has the authentication set to "none".

Todd Acheson
--
Todd Acheson

"Todd A" <ze**@olympus.com> wrote in message
news:OG****************@TK2MSFTNGP09.phx.gbl...
Oh, and another problem:

After the file is uploaded, if I have a link to this newly uploaded file,
and the user clicks on that link, they are prompted for WIndows Security
information (username, domain, and password).
But, if I publish that same file with FrontPage to the same directory
that
it was uploaded, the user is longer prompted for security, and the link
works fine.

Any advice?

--
Todd Acheson

================================
"Todd Acheson" <ta******@questared.com> wrote in message
news:13**********************@msnews.microsoft.com ...
> I'm having a small problem with uploading files in ASP.NET.
>
> My html page for uploading has something similar to:
>
> <form id="Form1" method="post" enctype="multipart/form-data"

runat="server">
> <input id="MyFile" type="file" runat="server" size="50">
> <asp:Button Runat="server" ID="btnUpload" Text="UPLOAD" />
> </form>
>
> . .and the corresponding vb.net code:
>
> Dim strFullPath As String
> strFullPath = MyFile.PostedFile.FileName
> Dim strFileName As String
> strFileName = Path.GetFileName(strFullPath)
> 'ViewState("strDirectory") might by a folder like "db/" or "pdf/"
> MyFile.PostedFile.SaveAs(ViewState("strDirectory") & strFileName)
>
> All very straighforward stuff that we've all used before.
>
> A file will upload just fine with the above code. The problem is, that

when
> the page comes back to the browser, all the CSS is lost. This is true in > both IE6 and FireFox 1.0. The design of the page(s) is a TableLess design > (no html tables). I have other projects where this worked fine, and
> the
> CSS wasn't lost, but the upload was in an html table. Since it happens in > both of these browsers, I'm thinking it isn't browser dependent??
>
> My question is: Is there something wrong with the above code that is

triggering
> the CSS to be lost? Is it a bug in ASP.NET?
>
> As a solution, I could probably redirect the user to a different page

indicating
> the results of their attempted file upload.
> Maybe I could try setting using:
> Response.Cache.SetCacheability(HttpCacheability.No Cache)
> at the top of the page?
>
> I appreciate any advice y'all can give.
>
> Thanks,
>
> Todd Acheson
>



Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.