Writing different Content Types to Response

I am writing the part of an application that will display documents that users have stored on the system. The types we allow or .tiff, , .PDF, Word, and Excel.
I am sending the contents of the file to the response with this code:
PrintWriter out = response.getWriter();
File file;
ServletContext sc = getServletContext();
String mimetype;               
file = new File(pathToFile);
mimetype = sc.getMimeType(pathToFile);
response.setContentType(mimetype);
// Read in the file and send chars to response
FileReader fReader = new FileReader(file);
char[] chars = new char[500];
while((fReader.read(chars)) != -1) {
     out.write(chars);
fReader.close();
out.flush();
out.close();The mime types I am using are
application/msword
application/vnd.ms-excel
application/pdf
image/tiff
Word works great. Excel sort of works. IE displays an error that data may be lost, but then displays the worksheet.
PDF half works. The table of contents displays in the left frame, but the right content frame is blank. And tiff only shows a distorted version of the image.
And it doesn't work in Firefox at all. I just get a blank frame regardless of the file type.
My question is, am I doing this correctly? Am I reading in the file and writing it back to the response the correct way? PDF and TIFF are working partially but not 100%. I feel like I am missing something.
Thanks,
Karl

Thanks a lot. It works perfectly now........in IE.
In Firefox PDF and images work ok, but for Word and Excel I get endless "Open With.." dialogs. Is this a plugin issue? I added the following line to my servlet with no change in result:
response.setHeader("Content-Disposition","inline");
Thanks,
Karl

Similar Messages

  • No support for content-type in response header?

    When loading both movies and images Strobe Media Playback does not recognize content-type from the response header.I can't find any documentation for this, but when i look in the source code, there sees to be support for this kind of metadata. For example in the "canHandelResource" function for ImageLoader has a "MIME_TYPES_SUPPORTED" vector that contains the type "image/jpeg". I can't see way, but this function is always falling back to checking the URL for file extensions.
    override public function canHandleResource(resource:MediaResourceBase):Boolean
                var rt:int = MediaTypeUtil.checkMetadataMatchWithResource(resource, MEDIA_TYPES_SUPPORTED, MIME_TYPES_SUPPORTED);
                if (rt != MediaTypeUtil.METADATA_MATCH_UNKNOWN)
                    return rt == MediaTypeUtil.METADATA_MATCH_FOUND;
                var urlResource:URLResource = resource as URLResource;
                if (urlResource != null &&
                    urlResource.url != null)
                    var url:URL = new URL(urlResource.url);
                    return (url.path.search(/\.gif$|\.jpg$|\.png$/i) != -1);
                return false;
    This makes it impossible to load an image (or movie) from a web-service that don't contain a file extension. Even though the response header from the request contains the correct "Content-type". Example response header:
    Date: Wed, 13 Jul 2011 08:07:26 GMT
    Server: Apache/2.2.17 (Unix)
    Cache-Control: max-age=60
    Expires: Wed, 13 Jul 2011 08:08:26 GMT
    Content-Length: 34010
    Content-Type: image/jpeg
    X-Pad: avoid browser bug
    200 OK
    Anybody that know way this is the case?

    There is no need for a constructor when all attributes are assigned.Unless there is a date value, apparently ;)
    It also works if you explicitly <tt>CAST(SYSDATE AS DATE)</tt> so perhaps the internal limitation is to do with the two internal DATE types (type 12 and 13, if you check DUMP output).

  • Help transmitting different content types to servlet

    Hi,
    I need to send data from my J2ME app to a servlet.
    Firstly, I need to send a bunch of text which is interpreted by the servlet and used to set various things. I can do this fine by setting the content type of the connection object to "application/x-www-form-urlencoded". After I have sent this data, I then need to send a byte array to the same servlet. I have read that this needs to be sent as "application/octet" type, but setting the header to that before closing the connection object throws an error, and fails to send anything to the servlet. How do I send multiple content types to the servlet? Do I need a new connection object? And if so how do I handle the servlet side of things to distinguish between both connections?
    Chris

    figured it out - i closed the first connection and opened another to send the binary data. then on the servlet I distinguished between the two by reading the request header to see what type of data was being sent at that time.

  • Specifying Content Type of the Response

    Can anyone enlist the different content type supported by browsers.
    In the Servlet, I need to set this to enable file download.
    My web application should supoort upload and download of files of any file type.

    http://www.ietf.org/rfc/rfc2045.txt

  • Tomcat always generates charset in Content-Type http header !!!

    Dear All! I need urgent help with a problem I met with and any suggestion are very appreciated!
    The problem is:
    We are using Tomcat as a web server (and JSP engine), and we would like to use a user control written in C# 2.0 on one of our pages. I've developed such component and tested it using JBuilderX (in fact it resides inside a JSP page). Everything is working fine while debugging using JBuilder, but when I tried to deploy the solution - I got a problem, my dll was not downloaded properly. Let me illustrate this with a test example. I wrote a test html page:
    <html > <head> <title>Test</title> </head> <body> <object id="MyControl" height="300" width="550" classid="http://localhost:8080/MyDLL.dll#WindowsControlLibrary1.UserControl1"> </object> </body> </html>
    When I tried to open it I did not get my control loaded. I check the headers of the server http response and found that Tomcat added the following string as
    Content-Type: application/x-msdownload;charset=ISO-8859-1
    I'm positive that in this case Content-Type should look like
    Content-Type: application/x-msdownload
    (or application/octet-stream if I would choose to define mime type for dll in server's web.xml as
    <mime-mapping> <extension>dll</extension> <mime-type>application/octet-stream</mime-type> </mime-mapping>
    - it does not matter as I understand )
    so Content-Type should not contain any charset for DLL part of response. NO charset=ISO-8859-1 !!
    But Tomcat adds it. :-( And I don't know how to prevent him doing that.
    On the other hand when I tried to open this page using Tomcat started from within JBuilder (port number in this case is different) - then everything was going good and control was downloaded to "Temporary Internet Files" and shown on the page.
    Content-Type field in this case was:
    Content-Type: application/x-msdownload
    without any charset.
    So, my question is: How to suppress Tomcat wish to add the "charset=ISO-8859-1" string to the Content-Type http response header?
    What should I do to load my test html page succesfully?
    Thanks in advance for you time and patience!
    Sincerely yours, Igor

    Back to the top

  • Issue with New Document in a document library with multiple content types

    Hi,
    I have a created a custom list definition based on a document library. I added 3 content types in this list, one is a document set (lets call it DOCSET), the two others are content types inheriting from Document (DOCA and DOCB).
    I deployed the list definition with a site scoped feature and the list instance with a web scoped feature. After activating the two features, the list is created and the content types are present in the list.
    When I click in the New Document button and choose either the DOCA or DOCB content type, a Word document opens and the DOCA content type is always associated to this Word document.
    With SharePoint Manager 2013 I saw that the template.dotx document was not in the Forms/DOCA or Forms/DOCB folder.
    So I decided to remove all the content types from the list definition and add them by code with the ListAdded event receiver. I used list.ContentTypes.Add to add the content types to the list.
    With this method the templates are correctly copied from the template.dotx in the RootFolder/Forms folder of my list. These templates have the rights content type id, but the New Document button still does not work properly.
    So I looked at the Content Types inside my library and saw that the DocumentTemplateUrl linked to the RootFolder/Forms/template.dotx and not the RootFolder/Forms/DOCA/template.dotx or RootFolder/Forms/DOCB/template.dotx.
    I debugged my code to look closer and see that right after the list.ContentTypes.Add, the DocumentTemplateUrl is correclty set but when my EventReceiver finishes, the DocumentTemplateUrl get back to the RootFolder/Forms/template.dotx.
    Have you any idea why this is not working ?
    Regards

    Hi,
    Per my understanding, there is an issue about the DOCA and DOCB content types which inherits from Document Content Type in your custom list definition.
    By default, if there is a custom content type inherits the OOTB Document Content Type, it will also inherits the template.dotx file from the OOTB Document Content Type.
    The template URL of a custom content type which inherits the OOTB Document Content Type:
    If you want to specify different templates for different content types, the code demo below would be helpful:
    http://www.learningsharepoint.com/2010/07/14/programmatically-create-a-new-content-type-in-sharepoint-2010/
    Thanks
    Patrick Liang
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Update Item when Content Type is changed in the browser

    I feel like I might be missing something obvious here - I set up a number of managed content types.  While editing a list item with multiple content types, when a user changes to a different content type using the drop down at the top of the page,
    the edits are not saved.  Is there any way to force an update when the user changes content type?  Clicking save returns the user to the list view which means the user needs to edit it again, and navigate to the content type.

    Hi Steve,
    Per my understanding, you might want to update item with the input values when content type changed by selecting an option in the “Content Type” drop down menu in
    EditForm.aspx page.
    A Content Type is a set of predefined columns, from the perspective of the use of Content Type in a list, it would be easier to maintain per record with only one content
    type as an item, this is also a recommended behavior when working with multiple content types in a list.
    If you want to take use of columns from multiple content types in an item, a suggestion is that you can create a custom content type with the columns from other content
    types you want, then add it into your list.  
    Thanks 
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Workflow attached to content type shows the status as 'Starting'

    Hi,
    I have developed a workflow to distribute documents from Drop Off library to different SharePoint libraries based on the content type that the document uploaded to.
    The drop off library has been configured incoming mail settings hence the documents would be on boarded to drop off library through e-mails. In this scenario, my workflow should be triggered when the document is on boarded through email.
    Another scenario, the user can upload the document to different content type manually and updates the respective meta data values. This scenario, my workflow should be triggered when the item updated.
    So, I have configured my workflow should run on the content types and trigger when item is created through e-mail and item is updated by manual.
    The document on boarded through e-mails are working fine as soon as the item is created.
    Issue:
    The workflow associated on a content type which needs to be triggered on item created is triggering as soon as the user uploads a document manually and shows the status as 'Starting'.
    The workflow associated on a content type which needs to be triggered on item modified is triggering as soon as the user updating meta data values after document is uploaded. Hence, throwing an error
    'cannot open a file from drop off' library exception when I try to read file using C# code as file stream bytes.
    Configuration:
    1. The content types are having mandatory fields which has a default values set.
    2. The document version settings are set as check out the document when editing the properties.
    Please help me to resolve this bug and let me know if you need more details.
    Also, let me know how can we cancel the workflow if it is in 'starting' mode.
    The workflow should run the document is onboardedwhen an item is created and

    Hi,
    According to your description, my understanding is that you want to get data from content type in JSlink.
    I suggest you can get the content type data in JSLink using JavaScript Client Object Model.
    Here are some derailed code demos for your reference:
    http://sharepoint.aspcode.net/view/635399286724222582163436/sharepoint-how-to-get-field-value-using-jsom-jslink-without-async-call
    http://sharepoint.stackexchange.com/questions/93777/how-to-get-contenttype-name-in-clientsidejavascript-jquery-csom-etc-in-editf
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • Filter SharePoint 2010 Ent. content types based AD Security Group

    We are trying to use SharePoint as a records management system. I have several site collections (Team Site at the root of each site) and my plan is to setup one site collection as a content type hub. The content type hub would then distribute all of the
    content types to my other site collections. Since I may have 70 different content types I want to filter what each user can see based on AD Security Groups (the SG matches the department the employee is in). This way they can only choose the content type that
    applies to their department and it won't be so confusing. I'll then apply retention policies based on content type. I know that I can apply retention policies based on the document library but I want the users to be able to organize their records however they
    want to.
    Am I taking the wrong approach? Is this possible?

     
    Hi,
    As far as I know, we can define the Permission Set on a content type. In this way, you can control which users or group can change or access which content types.
    For more information about SharePoint security and content type, see
    http://blog.contentmanagementconnection.com/Home/21510
    Thanks,
    Rock Wang
    Rock Wang TechNet Community Support

  • Dispform.aspx with content types

    SharePoint 2013 farm.
    I have two content types in a list. I need to change the dispform.aspx. 
    There are different fields for both content types, so copying the dispform.aspx to create and modify a new one is not a solution I think. I am not sure. i am new in this :)
    Can someone give me a step by step, how to modify the displayform of a list so that I can customize the the form for both content types.
    best regards,
    Olafur

    Hi  Olafur,
    There is a way in SharePoint Designer to specify which form the different content types in a list or library will use.
    Open up the list,  click on the content type name:
    On the Content Type screen, under the forms section, there is a text field where you can enter the relative path to the new form that you created.
    Reference:
    http://social.technet.microsoft.com/Forums/en-US/8f62d12d-8b72-40c7-baa4-59f4c211e86a/calendar-unique-newform-for-each-content-type?forum=sharepointgeneralprevious
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • Best Practises for using Content Types

    We had third party vendor who migrated and re structured contents and sites in Sharepoint 2010. I noticed one unusual thing : In most cases they new separate site content types for every library in a site i.e. even if two libraries contain same set of metadata
    columns they created separate site content types by duplicating it from the first one and gave it unique name and used in second library.
    My point of view for content type is that they are used for re usability, i.e. if another library is needing same set of metadata columns then I would just reuse existing content type rather than creating another content type with different name by inheriting
    it from the first one and having same set of columns.
    When I asked vendor reason for this approach (for every library they created new content types and for libraries needing same set of meta data columns they just inherited from a custom site content type and created another duplicate one with same set of
    meta data columns and gave it different name in most cases name of library ) they said they did that to classify documents which I did not agree with because by creating two document libraries classification is already done.
    I need some expert advice on this, I will really appreciate: I understand content types are useful and they provide re usability but,
     A) Do we need to create new site content types whenever we create new library ? (Even though we are not going to re use them)
    B) What is best practice : if few libraries are needing same set of metadata columns
    1) Create site a content type and reuse it in those libraries ? or
    2) Create a site content type and create new content types by inheriting from site content type created at first and just give them different name even though all of them are having same set of columns  ?
    I need expert advice on this but following is my own opinion on this
    I do not think point A) is a good practice and should not be used, we should create site content type only when we think it will be re used and we do not need to create site content type every time we create document library. Also I do not think point 2)
    of B is a good practice as well
    Dhaval Raval

    It depends on the nature of the content types and the libraries. If the document types really are shared between document libraries then use the same ones. If the content types are distinct and non overlapping items that have different processes, rules or
    uses then breaking them out into a separate content type is the way forward.
    As an example for sharing content types: Teams A and B have different document libraries. Both fill in purchase orders, although they work on different projects. In this case they use the same form and sharing a content type is the no question approach.
    As an example for different content types: A company has two arms, a consultancy where they send people out to client sites and a manufacturing team who build hardware. Both need to fill in timesheets but whilst the metadata fields on both are the same the
    forms are different and/or are processed in a different manner.
    You can make a case either way, i prefer to keep the content types simple and only expand out when there's a proven need and a user base with experience with them. It means that if you wanted to subdivide later you'd have more of a headache but that's a
    risk I generally think works out.

  • Document Sets and Content Types

    Hi All,
    I am having trouble in getting the "document sets" content types applied as expected when I try to create a site based off custom template.
    Scenario:
    We have 8 document sets stored in a document library. This library is part of a site which we have saved as a template.
    E.g. of document sets is "Others", "Meetings" etc
    Each of these document sets have one or more content types associated with it.
    We are trying to create a site based off the saved site template using powershell.
    E.g. $web = New-SPWeb http://myserver/sites/mysite/subsite
    $web.ApplyWebTemplate("{GUID}#Name of Template")
    When we open the document sets in this newly created site, the content types seem to be coming all together rather than being associated with the specific document set.
    E.g. Clicking "New document" in the "others" document set would show up content types from "meeting" and all the remaining document sets present in that library.
    Interestingly, when I go to "Document Set" settings, I only see the content type of "Others" Document Set.
    Any idea why the "New document" dropdown for the document set is not behaving as expected?

    Hi Abhi,
    Based on your description, I did a test. In my testing, everything worked well.
    The steps are:
    Go to Site Actions->Site Settings->Site content types.
    Create a new content type, and select parent content type from Document Set Content Types, and Parent Content Type: Document Set
    Click ok
    Under Settings, click Document Set settings
    On the Allowed Content Type section, select some content types and add them
    Click OK
    Then repeat step2-6, and create another custom document set
    Open your library, and allow management of content types in advanced settings
    Add the two document sets into the library
    Check each document set, and each one had different content types
    Save the site as a template and include the content
    Create a new site based on the site template using PowerShell(the command was same with yours)
    After creating, check the document sets of the library in the new site, everything worked well.
    Please check your process as the above steps.
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Content Type Question

    I created a term set called 'Document Category' that has 10 different terms (e.g. Quote, Agreement, Diagram, etc.) that describe the types of documents users save into our main document library. I then created 10 different Content Types, each with it's
    own template, so, from the doc library, users can click Files > New, and choose the appropriate content type to create a document. I want to be able to sort in the library using a custom column I created, called 'Document Category', that links to the 'Document
    Category' managed metadata term set. When users create a new document based on one of the content types, I want the 'Document Category' field automatically populated in the Document Information Panel with the correct term. My problem is that I can't find a
    way of getting each individual content type to default to it's matching term. I can set the custom column to use a default value (e.g. Quote) so it comes up automatically filled in for the 'Quote' content type. Because I'm linking the 'Agreement' content type
    to the same custom column, though, it obviously then defaults to 'Quote', too. I was hoping to have a different term linked to each content type. Does anyone know how to do this? Any help would be greatly appreciated! -Pete

    Hi,
    According to your post, my understanding is that you wanted to set the 'Document Category' field automatically.
    I recommend to create SharePoint 2010 Platform workflow and then set an empty Managed Metadata column using the following format: Term Name| Unique Identifier based on the item content type.
    You can create workflow as below and start the workflow automatically when an item is created:
    Thank you for your understanding.
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Set content type in respone

    Hi,
    I am using velocity model and to set the content type of response as csv report i am setting content type of response as
    $response.setContentType("application/vnd.ms-excel")
    This stmt opens up open-save download dialog box. But the problem is a new internet browser window also opens up. I want to hide this newly opened browser till i click on open button.
    How i can hide or disable this IE window.

    Ritu,
    U specified only content type , try to specifiy attributes like attachment where u can rid of the IE explorer.
    if u have any other doubts u r most welcome giving me a mail [email protected]
    Thanks.
    Sravan

  • Assign new default forms to list causes other content types forms to fail.

    I have a list with multiple content types and I want to modify the forms.   I've created new forms but when I assign them as default and go back to the new item menu, no matter which item I select I get the new default form.  If I set the
    NewForm.aspx back as default everything works.
    How can I modify for one content type and ensure the forms are not affected?
    By modify I mean I want to put a hyperlink on one of the forms but not the other.

    Form libraries can be very painful if you can't foresee the direction that the form will be evolving over time.  I've run into times when users have been using a form for months - years, and then a sudden change is needed (such as a change in calculations)
    that they want to show ONLY in new forms, and the old calculations (for the same calculated fields) to show up in the old form, and you can't have 2 different versions of the same form working on a library unless you use content types. 
    You also, however, need to plan for columns and column types because of limitations around the number of Int columns or date/time columns, etc... that are allowed in a list.  If you plan on using content types, I would say use a base content type (if
    the content types will have the same fields) and then the fewer fields are different, the fewer columns are required on the library.  In different content types, you can use different forms, and then you can make different calculations within the forms
    for the same field (if that is ever a requirement). 
    Its best to plan this out ahead of time, because switching strategy after running for a while can create monstrous headaches.

Maybe you are looking for