Here's code from a production app that has been running for nearly a year that serves PDFs. We noticed some problems with IE 5.5 without the latest service packs. However, no server-side problems. Document CurrentDoc = Document.Find(currentArea, currentUser, DocumentID); string TempFilePath = ConfigurationSettings.AppSettings["TempDir"] + "/" + SessionID + "/" + CurrentDoc.FileName; if (Method == "View") { LogEntry.Save(currentUser, CurrentDoc, LogEntry.AccessTypeEnum.View, DateTime.Now); Response.AddHeader("Content-Disposition", "inline;filename=" + CurrentDoc.FileName); } else { LogEntry.Save(currentUser, CurrentDoc, LogEntry.AccessTypeEnum.Download, DateTime.Now); Response.AddHeader("Content-Disposition", "attachment;filename=" + CurrentDoc.FileName); } // Serve it CurrentDoc.SaveDocContentsToFile(TempFilePath); Response.AddHeader("Content-Length", CurrentDoc.FileSize.ToString()); Response.ContentType = CurrentDoc.ContentType; Response.WriteFile(TempFilePath); Response.End(); Andy Hochstetler
Andy Hochstetler
Posts
-
Write Binary Files to the Browser -
Write Binary Files to the BrowserRT1970 wrote: I tried to write binary files to the browser based on the codes found in Microsoft Knowledge Base Article 306654: //Set the appropriate ContentType. Response.ContentType = "Application/pdf"; //Get the physical path to the file. string FilePath = MapPath("acrobat.pdf"); //Write the file directly to the HTTP content output stream. Response.WriteFile(FilePath); Response.End(); The codes works for many kinds of file types, like DOC, PPT, XLS... but not for PDF. When it's a PDF file, Response.End will throw a ThreadAbortException because "the current response ends prematurely". I also tried BinaryWrite, Flush, no difference. Anyone has any suggestion?
Have you tried setting the ContentLength? I had a similar problem with PDFs and setting this property to the actual file size cured the problem for me.
Andy Hochstetler
-
Coding StylePaul Watson wrote: To be honest I have variable naming diarrhea. e.g. a TextBox for a first name is textboxFirstName. I do trim it though if the class name is too long (like SqlDataReader).
I've followed the Microsoft documentation where I append my data type to the end. Usually, it's something like this: FirstNameTextBox, YesNoCheckBox or maybe MyCustomException. That's for local variables. For instance variables and parameter values, I use the camel casing, so I might have a variable called sampleTextBox. Using the different casing helps me to identify scope. Andy Hochstetler
-
Problems with Exception Management Application BlockI'm having difficulty getting the Microsoft Application Block for Exception Management working. In particular, I'm trying to customize the DefaultPublisher so that it uses a custom log source in the EventLog. Here are some of my constraints, many of which I've overcome. 1) I wanted the assembly deployed to the GAC so that more than one app could share it. 2) My apps are web apps, so I had to deal with security issues regarding getting a custom log source set up. OK, so I created my strong names for the ExceptionManagement and Interfaces assemblies, and got both installed to the GAC. No problem. I used the INSTALLUTIL.EXE to run the custom installer for the ExceptionManagement assembly. So far so good. I manually created the registry key and string value for my log source. Next, I set up the web.config file. Here's the way I had it set up the first time:
Now when I generated an exception, several were logged using my custom log source, including several that it was unable to find the type for the section handler. Well, I figured out that it was because I had an assembly in the GAC and hadn't fully qualified the names. So I fixed the web.config to be:
Well, now to the point I'm at now. I get an internal exception that has the following detail. I'm at wits end! Any help would greatly be appreciated!!! Thanks, Andy 1) Exception Information *****************************************