Link to home
Start Free TrialLog in
Avatar of dcass
dcassFlag for United States of America

asked on

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

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);
            }
Avatar of dcass
dcass
Flag of United States of America image

ASKER

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.
Avatar of David H.H.Lee
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/
Avatar of dcass

ASKER

I get an error that says "the type or namespace name 'FileStream' could not be found.  Are you missing an assembly reference or directive?"
Avatar of dcass

ASKER

Oh - this is asp 1.1 in case that matters.
Dear dcass,
You need to import System.IO or you can call it directly System.IO.FileStream
Avatar of dcass

ASKER

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.
Avatar of dcass

ASKER

The file and folder security is read for everyone.
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.
Avatar of dcass

ASKER

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.
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?
Avatar of dcass

ASKER

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?
Avatar of dcass

ASKER

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.
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.
Avatar of dcass

ASKER

did all - full permissions.
Dear dcass,
How about IIS Setting and your application's authentication setting? Can you provide more details about that?  
Avatar of dcass

ASKER

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>  
Dear dcass,
Seem that's strange issue. Ok, what pdf version you've installed in your pc?
Avatar of dcass

ASKER

Adobe reader 8 on my pc but I'm on remote services on this server - no adobe installed that I can find.
ASKER CERTIFIED SOLUTION
Avatar of David H.H.Lee
David H.H.Lee
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dcass

ASKER

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.
Avatar of dcass

ASKER

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!
Dear dcass,
Welcome. I'm glad to help.