473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

File downloading problem.

Hi

I am trying to download the PDF files from my webserver using ASP.Net.

All my files are stored at F Drive on webserver. Like this F:\Main
Folder\Sub Folder\Files\File1.pdf

I am impersonating the domain user account and downloading the file, It
seems the impersonate is got success, but its not download the file. Its
simply downloading some junk pdf file instead of original file.

I gave the all permission to all domain user accounts to Main Folder.

Here is the code I am using.
If impersonateValidUser(Session("WinLogin"), "domainName",
Session("WinPassword")) Then
DownloadFile(CType(E.Item.Cells(0).Controls(0),
HyperLink).NavigateUrl, True)
undoImpersonation()
Else
' impersonation failed.
Response.Write("not ok")
End If

-----------

Private Sub DownloadFile(ByVal fname As String, ByVal forceDownload As
Boolean)
Dim path1 As String = fname
Dim name As String = Path.GetFileName(path1)

Dim ext As String = Path.GetExtension(path1)
Dim type As String = "Application/pdf"
If forceDownload Then
Response.AppendHeader("content-disposition", "attachment;
filename=" & name)
Else
Response.AppendHeader("content-disposition", "inline;
filename=" & name)
End If
Response.WriteFile(path1)
Response.End()
End Sub

Thanks
Balakumar

Nov 19 '05 #1
2 2405
you should clear content and headers.
Response.ClearHeaders();
Response.ClearContent();

otherwise the html markup on the page is sent before your pdf content.

note: Response.End(), kills the thread, so no code after Response.End runs.

If impersonateValidUser(Session("WinLogin"), "domainName",
Session("WinPassword")) Then
DownloadFile(CType(E.Item.Cells(0).Controls(0),
HyperLink).NavigateUrl, True)
undoImpersonation() '<-- this code never runs
Else
' impersonation failed.
Response.Write("not ok")
End If
"Bala" <Ba**@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
Hi

I am trying to download the PDF files from my webserver using ASP.Net.

All my files are stored at F Drive on webserver. Like this F:\Main
Folder\Sub Folder\Files\File1.pdf

I am impersonating the domain user account and downloading the file, It
seems the impersonate is got success, but its not download the file. Its
simply downloading some junk pdf file instead of original file.

I gave the all permission to all domain user accounts to Main Folder.

Here is the code I am using.
If impersonateValidUser(Session("WinLogin"), "domainName",
Session("WinPassword")) Then
DownloadFile(CType(E.Item.Cells(0).Controls(0),
HyperLink).NavigateUrl, True)
undoImpersonation()
Else
' impersonation failed.
Response.Write("not ok")
End If

-----------

Private Sub DownloadFile(ByVal fname As String, ByVal forceDownload As
Boolean)
Dim path1 As String = fname
Dim name As String = Path.GetFileName(path1)

Dim ext As String = Path.GetExtension(path1)
Dim type As String = "Application/pdf"
If forceDownload Then
Response.AppendHeader("content-disposition", "attachment;
filename=" & name)
Else
Response.AppendHeader("content-disposition", "inline;
filename=" & name)
End If
Response.WriteFile(path1)
Response.End()
End Sub

Thanks
Balakumar

Nov 19 '05 #2
I did the changes. But still its not downloading the files.
here is the code which I am using.

Response.ClearHeaders()
Response.ClearContent()

If impersonateValidUser(Session("WinLogin"), "ScanFiles.local",
Session("WinPassword")) Then
Dim spath As String
spath = CType(E.Item.Cells(0).Controls(0),
HyperLink).NavigateUrl
Try
If File.Exists(spath) Then
Response.Write("File exists")
Else
Response.Write("no exist")
End If
Catch ex As System.Exception
Response.Write(ex.ToString)
End Try
DownloadFile(CType(E.Item.Cells(0).Controls(0),
HyperLink).NavigateUrl, True)
Else
' impersonation failed.
Response.Write("not ok")
End If
'-------------------------------------
Private Sub DownloadFile(ByVal fname As String, ByVal forceDownload As
Boolean)
Dim path1 As String = fname
Dim name As String = Path.GetFileName(path1)

Dim ext As String = Path.GetExtension(path1)
Dim type As String = "Application/pdf"
If forceDownload Then
Response.AppendHeader("content-disposition", "attachment;
filename=" & name)
Else
Response.AppendHeader("content-disposition", "inline;
filename=" & name)
End If
'
Response.Write(System.Security.Principal.WindowsId entity.GetCurrent().Name())
Response.WriteFile(path1)
'Response.End()
End Sub
'------------------------------ code end

"Bruce Barker" wrote:
you should clear content and headers.
Response.ClearHeaders();
Response.ClearContent();

otherwise the html markup on the page is sent before your pdf content.

note: Response.End(), kills the thread, so no code after Response.End runs.

If impersonateValidUser(Session("WinLogin"), "domainName",
Session("WinPassword")) Then
DownloadFile(CType(E.Item.Cells(0).Controls(0),
HyperLink).NavigateUrl, True)
undoImpersonation() '<-- this code never runs
Else
' impersonation failed.
Response.Write("not ok")
End If
"Bala" <Ba**@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
Hi

I am trying to download the PDF files from my webserver using ASP.Net.

All my files are stored at F Drive on webserver. Like this F:\Main
Folder\Sub Folder\Files\File1.pdf

I am impersonating the domain user account and downloading the file, It
seems the impersonate is got success, but its not download the file. Its
simply downloading some junk pdf file instead of original file.

I gave the all permission to all domain user accounts to Main Folder.

Here is the code I am using.
If impersonateValidUser(Session("WinLogin"), "domainName",
Session("WinPassword")) Then
DownloadFile(CType(E.Item.Cells(0).Controls(0),
HyperLink).NavigateUrl, True)
undoImpersonation()
Else
' impersonation failed.
Response.Write("not ok")
End If

-----------

Private Sub DownloadFile(ByVal fname As String, ByVal forceDownload As
Boolean)
Dim path1 As String = fname
Dim name As String = Path.GetFileName(path1)

Dim ext As String = Path.GetExtension(path1)
Dim type As String = "Application/pdf"
If forceDownload Then
Response.AppendHeader("content-disposition", "attachment;
filename=" & name)
Else
Response.AppendHeader("content-disposition", "inline;
filename=" & name)
End If
Response.WriteFile(path1)
Response.End()
End Sub

Thanks
Balakumar


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ASP Spam Fighter | last post by:
Hello all, I don't know how to get around this one... If anybody can help me with this problem, I would appreciate it very much. I've been trying to send a (large) file to the browser via a...
2
by: serge | last post by:
Is this the correct newsgroup for this posting? I have a problem when using these lines of code: Dim xmlhttp as Object set xmlhttp = CreateObject("Microsoft.XMLHTTP") Call...
5
by: Tim_Mac | last post by:
hi, i read that by adding the following code to by aspx pages, it would not store temporary internet files: Response.Cache.SetCacheability(HttpCacheability.NoCache); it didn't actually work...
1
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
3
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
2
by: Tomas Martinez | last post by:
Hi there! I'm trying to download a file in my asp.net web, but when downloading it from a Firefox browser, instead of downloading the example.exe file, it's downloading example.exe.htm. My code...
6
by: rony_16 | last post by:
Hi, I have problem with downloading a file using WebRequest and HttpWebResponse. Inorder to download this file i need to call to url that tells to prepare the file for download, and then i call...
1
by: Muddasir | last post by:
Hello everyone. I am facing problem in downloading .xls file. I generate report and save data in excel sheet on server. and once user click the 'save data in excel format', an excel sheet is...
1
by: shahidrasul | last post by:
i want to download a file which user select from gridview, downloading is completing without problem but after download i want to refresh my page because i do some changes in db . but when...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.