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

File downloading problem.

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.