?
Solved

C# .net - Redirect has Save instead of just opening PDF, any, n/a

Posted on 2007-08-07
22
Medium Priority
?
300 Views
Last Modified: 2013-11-05
Reponse.Redirect is trying to function as a download instead of just opening the URL for a PDF.
What am I doing wrong?
<asp:LinkButton id="Linkbutton1" runat="server">
<img src="userfiles/image/pdf.gif"></asp:LinkButton>Attachment 1:

            private void LinkButton1_Click(object sender, System.EventArgs e)
            {
                  string [] splitImage = this.Text1.Text.Split(new Char [] {'\\'});
                  string splitI4 = splitImage[5];
                  Response.Redirect("~/userfiles/"+splitI4);
            }
0
Comment
Question by:dcass
  • 13
  • 9
22 Comments
 

Author Comment

by:dcass
ID: 19650988
and I tried using the full path and it still asked if I wanted to Save or Cancel instead of opening the PDF in the browser - have to use IE in this app.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 19651031
Dear dcass,
You can create a new page to render pdf file inside the content.
eg:

public void Page_Load{
FileStream MyFileStream;
                  int FileSize;
                  string filePath = Server.MapPath("userfiles/"+Request["yourfile.pdf"]); //"YOURFILE.PDF";

                  MyFileStream = new FileStream(filePath, FileMode.Open);
                  FileSize = (int) MyFileStream.Length;

                  Byte[] Buffer = new Byte[FileSize];
                  MyFileStream.Read(Buffer, 0, FileSize);
                  MyFileStream.Close();

                  Response.ContentType = "application/pdf";
                  Response.OutputStream.Write(Buffer, 0, FileSize);
                  Response.Flush();
                  Response.Close();
}

Or,
Please check this site for another alternative:
Filling and processing Adobe PDF Forms with iTextSharp
http://asp-net-whidbey.blogspot.com/
0
 

Author Comment

by:dcass
ID: 19651067
I get an error that says "the type or namespace name 'FileStream' could not be found.  Are you missing an assembly reference or directive?"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:dcass
ID: 19651071
Oh - this is asp 1.1 in case that matters.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 19651079
Dear dcass,
You need to import System.IO or you can call it directly System.IO.FileStream
0
 

Author Comment

by:dcass
ID: 19651325
It is now attempting to open it (I think) but before it does, it keeps asking me over and over for my user name/password - the Windows function, and it won't accept a valid entry.
0
 

Author Comment

by:dcass
ID: 19651352
The file and folder security is read for everyone.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 19651369
Dear dcass,
You can turn off Integrated Windows Authentication inside IIS setting and see the result.
eg:IIS->Directory Security->Anonymous access and authencation control->Edit->
Check Anonymous access
Unchecked Integrated Windows authencation.
If that not solve the issue, tell me what's is your application's authencation mode. Let see how the retrify this security problem.
0
 

Author Comment

by:dcass
ID: 19651560
I found this.  How does this translate into c#?
<%
Response.ContentType = "image/jpeg"
Set oStream = Server.CreateObject("ADODB.Stream")
Response.BinaryWrite oStream.LoadFromFile("C:\afterWF.jpg").Read
oStream.Close : Set oStream = Nothing
%>

It looks like exactly what I need.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 19652090
Dear dcass,
Here the translation result:
using ADODB;

Response.ContentType = "image/jpeg";
ADODB.Stream oStream = new ADODB.StreamClass();
oStream.LoadFromFile(@"C:\afterWF.jpg");
Response.BinaryWrite(oStream.Read);
oStream.Close() ;

Btw, i thought u want to display pdf result only?
0
 

Author Comment

by:dcass
ID: 19654057
Yes, I am using your code - just wanted to understand the difference.
When I removed Windows authentication, it said I couldn't use debug - that's a problem except that .net also started giving me the error that I was not in debugger users group - just all of a sudden - no changes to system or .net.
I think I'm having trouble with the path.  My pdf is in a subfolder - how should I structure the path?
0
 

Author Comment

by:dcass
ID: 19654132
Also, I'm getting "Access to the path 'C:\Inetpub\wwwroot\myfolder' is denied" on MyFileStream = new FileStream(filePath, FileMode.Open);  even though I've given asp.net all security and also all other users (including everyone) and it still gives it.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 19654196
Dear dcass,
What is the permission that you've granted? To solve the security issue, you need to grant ASP.NET permission.If you're using window 2003 then give all permission to IUser_<Machine> account. For winXP, you need to give permission to Network_Service account.
0
 

Author Comment

by:dcass
ID: 19654245
did all - full permissions.
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 19654308
Dear dcass,
How about IIS Setting and your application's authentication setting? Can you provide more details about that?  
0
 

Author Comment

by:dcass
ID: 19654488
Are you sure this is not a mime problem?  There is nothing on this system that I can find to open a pdf - only IE comes up as an option.  When I go to the folder and click on the pdf and choose IE, it still will not display.

Directory settings in IIS are "Enable anonymous access". Nothing else is checked.

web.config:    
<identity impersonate="true"/>
<authentication mode="Forms">
     <forms loginUrl="Secure/Login.aspx" slidingExpiration="true" requireSSL="false"/>
 <authorization>
        <allow users="*" />
</authorization>
    </authentication>  
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 19654553
Dear dcass,
Seem that's strange issue. Ok, what pdf version you've installed in your pc?
0
 

Author Comment

by:dcass
ID: 19654597
Adobe reader 8 on my pc but I'm on remote services on this server - no adobe installed that I can find.
0
 
LVL 29

Accepted Solution

by:
David H.H.Lee earned 1000 total points
ID: 19654670
Dear dcass,
Do you have the right to install pdf at your remote server? If yes, you need to install it in order to view the pdf file correctly via IE Browser.
It's free for installation. http://www.adobe.com/products/acrobat/readstep2.html.
After install, that should be working fine after that.
0
 

Author Comment

by:dcass
ID: 19654686
Does adobe reader have to be installed on the server for FileStream in my app to work when remoted in?  The users are connected locally when they run it, so they may not even be having this problem?   If that's the case, I should stop messing with this authority problem and just leave it at response.redirect to the pdf.  They are getting very anxious about getting this project turned over to production.
0
 

Author Comment

by:dcass
ID: 19658972
That was it - it worked fine for them - it just couldn't work for me being remoted in.  It took me a while to figure it out.
Since being remoted in was the key and you couldn't know that, and because I really appreciate your effort - you get the points!
0
 
LVL 29

Expert Comment

by:David H.H.Lee
ID: 19659253
Dear dcass,
Welcome. I'm glad to help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question