473,769 Members | 5,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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\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

Nov 19 '05 #1
2 2436
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

Nov 19 '05 #2
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


Nov 19 '05 #3

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

Similar topics

1
3230
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 download page that uses a file download component. The file downloads fine, except that Internet Explorer refuses to browse to a different page while the file is downloading! I don't understand why it does that and I don't know how to fix this...
2
2390
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 xmlhttp.Open("GET", Application.Profiles.ActiveProfile.Server & "/Test.abc", False): Call xmlhttp.send("");
5
9150
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 that way, but i left it in anyway. little did i know it would cause a problem for a forced download routine i have. instead of downloading the .xls attachment, it tried to download the aspx file, and gave an error saying the file could not be...
1
2083
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 any page from the server while downloading. If I try to call a single page while downloading a file then the page request goes time out and the server then closes the existing download stream and the client doestn't throw any exception. So many a...
3
2792
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 any page from the server while downloading. If I try to call a single page while downloading a file then the page request goes time out and the server then closes the existing download stream and the client doestn't throw any exception. So many a...
2
2776
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 is the following: string localfile = MyComponent.DownloadMyExe(index); Response.ClearContent(); Response.ClearHeaders(); Response.ContentType="application/octet-stream";
6
414
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 to another url that downloads the file. I have a problem with that because: 1. i do not know when the server finished the preparetion. 2.i checked the HttpStatusCode but he doen't changes
1
1686
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 been created on the server.once created then user can download that file. i am able to download file but the problem is that when user apply sorting to data and then save data in excel sheet. the file on the server contains the data in the same...
1
3535
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 refresh.redirect() occure it give me error that can't redirect because headers have been sent following are my code to download file
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.