I did the changes. But still its not downloading the files.
here is the code which I am using.
Response.ClearH eaders()
Response.ClearC ontent()
If impersonateVali dUser(Session(" WinLogin"), "ScanFiles.loca l",
Session("WinPas sword")) Then
Dim spath As String
spath = CType(E.Item.Ce lls(0).Controls (0),
HyperLink).Navi gateUrl
Try
If File.Exists(spa th) Then
Response.Write( "File exists")
Else
Response.Write( "no exist")
End If
Catch ex As System.Exceptio n
Response.Write( ex.ToString)
End Try
DownloadFile(CT ype(E.Item.Cell s(0).Controls(0 ),
HyperLink).Navi gateUrl, True)
Else
' impersonation failed.
Response.Write( "not ok")
End If
'-------------------------------------
Private Sub DownloadFile(By Val fname As String, ByVal forceDownload As
Boolean)
Dim path1 As String = fname
Dim name As String = Path.GetFileNam e(path1)
Dim ext As String = Path.GetExtensi on(path1)
Dim type As String = "Applicatio n/pdf"
If forceDownload Then
Response.Append Header("content-disposition", "attachment ;
filename=" & name)
Else
Response.Append Header("content-disposition", "inline;
filename=" & name)
End If
'
Response.Write( System.Security .Principal.Wind owsIdentity.Get Current().Name( ))
Response.WriteF ile(path1)
'Response.End()
End Sub
'------------------------------ code end
"Bruce Barker" wrote:
you should clear content and headers.
Response.ClearH eaders();
Response.ClearC ontent();
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 impersonateVali dUser(Session(" WinLogin"), "domainName ",
Session("WinPas sword")) Then
DownloadFile(CT ype(E.Item.Cell s(0).Controls(0 ),
HyperLink).Navi gateUrl, True)
undoImpersonati on() '<-- this code never runs
Else
' impersonation failed.
Response.Write( "not ok")
End If
"Bala" <Ba**@discussio ns.microsoft.co m> wrote in message
news:95******** *************** ***********@mic rosoft.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\Fi le1.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 impersonateVali dUser(Session(" WinLogin"), "domainName ",
Session("WinPas sword")) Then
DownloadFile(CT ype(E.Item.Cell s(0).Controls(0 ),
HyperLink).Navi gateUrl, True)
undoImpersonati on()
Else
' impersonation failed.
Response.Write( "not ok")
End If
-----------
Private Sub DownloadFile(By Val fname As String, ByVal forceDownload As
Boolean)
Dim path1 As String = fname
Dim name As String = Path.GetFileNam e(path1)
Dim ext As String = Path.GetExtensi on(path1)
Dim type As String = "Applicatio n/pdf"
If forceDownload Then
Response.Append Header("content-disposition", "attachment ;
filename=" & name)
Else
Response.Append Header("content-disposition", "inline;
filename=" & name)
End If
Response.WriteF ile(path1)
Response.End()
End Sub
Thanks
Balakumar