Download/Upload Multi-valued property using Code

We are developing program that will download document properties from one Portal Server and upload document properties to another server.
Can someone provide a code snipplet on how to deal with multi-valued property for this download/upload requirement.
1. How do we download property values for Multi-valued properties for document.
2. How do we upload property values for Multi-valued properties for document.

We were able to do this.  This bug is fixed by SAP in 7.0 ICE.

Similar Messages

  • Setting multi-value parameters using ReportExecutionService

    Does anyone know how to set multi-value parameters using ReportExecutionService in C#?
    If I have
    rsExec = new ReportExecutionService2005.ReportExecutionService();
    ReportExecutionService2005.ParameterValue[] parameters = new ReportExecutionService2005.ParameterValue[2];
    parameters[0] = new ReportExecutionService2005.ParameterValue();
    parameters[0].Label = "Report_Begin_Date";
    parameters[0].Name = "Report_Begin_Date";
    parameters[0].Value = "4/15/2007";
    parameters[1] = new ReportExecutionService2005.ParameterValue();
    parameters[1].Label = "SalesID";
    parameters[1].Name = "SalesID";
    parameters[1].Value = ???  //Here, this parameter should accept multiple values like 200, 201, 202, etc.
    rsExec.SetExecutionParameters(parameters, "en-us");
    How would I set the SalesID to take multiple values?

    hi
    how to set dynamic parameters values.
    please help me.
    reportexe.
    ParameterValue[] parameters =
    new reportexe.ParameterValue[5];
    if (_parameters.Length > 0)
    parameters[0] =
    new reportexe.ParameterValue();
    parameters[0].Label =
    "mgrid";
    parameters[0].Name =
    "mgrid";
    parameters[0].Value =
    "[DMMGR001MT].[MGR ID].&[10]";
    parameters[1] =
    new reportexe.ParameterValue();
    parameters[1].Label =
    "locid";
    parameters[1].Name =
    "locid";
    parameters[1].Value =
    "[DMDPT001MT].[DPT ID].&[700]";
    //[DMDPT001MT].[DPT ID].&[700] 
    parameters[2] =
    new reportexe.ParameterValue();
    parameters[2].Label =
    "usrid";
    parameters[2].Name =
    "usrid";
    parameters[2].Value =
    "[FILLED BY USER].[USER ID].&[yshah]";
    //[FILLED BY USER].[USER ID].&[yshah] 
    parameters[3] =
    new reportexe.ParameterValue();
    parameters[3].Label =
    "fromdate";
    parameters[3].Name =
    "fromdate";
    parameters[3].Value =
    "[FIRST DOSE DATE].[Date Key].&[20100101]";
    //[FIRST DOSE DATE].[Date Key].&[20100101] 
    parameters[4] =
    new reportexe.ParameterValue();
    parameters[4].Label =
    "todate";
    parameters[4].Name =
    "todate";
    parameters[4].Value =
    "[FIRST DOSE DATE].[Date Key].&[20100131]";
    // [FIRST DOSE DATE].[Date Key].&[20100131]
    this is my code.
    indu

  • How to create a multi value property

    Hello,
    I've defined a new property to use with the FAQ form, and set it to a multi value enabled (Multi-Valued checkbox on, Property Renderer set to multivalued).
    I've added a new Combo Box object to the form using Form Builder, and assign the property to it.
    However, I'm able to choose only one value while creating a new FAQ.
    What should I do in order to make it a multi value selection box (without programming) ?
    Thanks
    Eli

    Hi,
    You have to use the PortalApp.xml file
    In that file you have to create the properties and can have n options, it will not require programming.
    <?xml version="1.0" encoding="utf-8"?>
    <application>
      <application-config/>
      <components>
        <component name="Welcome">
          <component-config>
            <property name="ClassName" value="com.sap.tutorial.Welcome.Welcome"/>
          </component-config>
          <component-profile>
            <property name="colorName" value="Blue">
              <property name="personalization" value="dialog"/>
              <property name="type" value="select[Red,Orange,Green,Blue,Yellow,Purple,Violet]"/>
              <property name="plainDescription" value="Favorite Color"/>
            </property>
            <property name="location" value="Pune">
              <property name="personalization" value="dialog"/>
              <property name="plainDescription" value="Country of Residence"/>
            </property>
            <property name="petsName" value="Tommy">
              <property name="personalization" value="dialog"/>
              <property name="plainDescription" value="Pets Name"/>
            </property>
          </component-profile>
        </component>
      </components>
      <services/>
    </application>
    Regards,
    Dhruv Shah

  • Multi valued property metadata modifying using Portal Drive

    Hi All,
    We are analyzing Portal Drive tool for KM.
    We have multivalued properties for files say geo:USA, APAC etc... Once we give value to geo property by being online in portal drive it is not reflectiong in Portal.
    We are not able to view geo value in property through network mapped drive even if we maintain value in KM manually.
    Please guide.
    Thanks and Regards,
    Ganga.

    We were able to do this.  This bug is fixed by SAP in 7.0 ICE.

  • Retrieving empty values from multi value string in user profile custom properties

    Hi,
    I created a webpart to save and retrieve data from custom properties. I use the code below to get the stored data:
    for (int i = 0; i < profile[property].Count; i++)
    Item = profile[property][i] == null ? string.Empty : profile[property][i].ToString();
    list.Add(Regex.Split(Item, @"\,\#"));
    Nothinig special about it.
    In my development environment, it works fine. The problem is  in my UAT environment. I'm facing an issue that i hope someone has been through. When the custom property is a multi value string type, it returns a empty string. I tested with HTML and single
    value fields and it works fine.
    Independently of the field type, it saves the data all right.
    Can anyone help me?
    Thanks!!

    Thanks, Chitvan Jain.
    I did as you suggested, but nothing changed. The problem is that profile[propname] comes already blank when using multi value property, even if there is data  to be retrieved.
    One funny thing is that, somehow the code manages to count the number of values there is in the property. Only the data is missing. We can see the exact number of column, cause i check if there's the right number of data, if there isn't, i add up  a empty
    string on the grid cell, but only for viewing. The empty string is not stored in the property.

  • Insert Value(s) in Lookup Flat Multi-valued Table with Java API

    I've been looking in MDM Java API Library Reference Guide, MDM SP4 API JavaDoc, and SDN Forums for information on how to Insert/Update different values in a field in the Main Table of a given repository that belongs to a Lookup Flat Multi-valued Table using the Java API with no success.
    I also haven't been successful in adding this values in the same way that I'll add a single value, using the MDM Java API, in a single-value Lookup Table (a2iFields.Add(new A2iField(FIELD_CODE,FIELD_VALUE)) for each value I want to add, like for example:
    a2iFields.Add(new A2iField("Country","USA")
    a2iFields.Add(new A2iField("Country","Mexico")
    a2iFields.Add(new A2iField("Country","Germany")
    Can anybody point me to the correct documentation that I need to read to fulfill this task? Or, even better, if someone can post a piece of code, I'll be more thankful.
    Thanks for your help.

    HI,
    little code example, where you add existing lookup values based on there record id:
         int USA = 1;
                        int GERMANY = 2;
                        A2iValueArray countryArray = new A2iValueArray();               
                        countryArray.Add(new Value(USA));
                        countryArray.Add(new Value(GERMANY));
                        A2iFields record = new A2iFields();
                        record.Add(new A2iField("Country", new Value(countryArray)));
    Please reward points if helpful.
    Regards,
    Robert

  • Handling multi-value parameters in VS 2005 / Crystal 2008

    In my program I am trying to handle a multi-value parameter using the following code, passing it an array of type string with the values that the user selected, but using the following code returns a 'Missing parameter values' error.
        For Each crParameterFieldDefinition In crParameterFieldDefinitions
            If Not crParameterFieldDefinition.IsLinked And crParameterFieldDefinition.ReportName = "" Then
                crParameterValues = crParameterFieldDefinition.CurrentValues
                crParameterDiscreteValue = New ParameterDiscreteValue
                If crParameterFieldDefinition.EnableAllowMultipleValue Then
                    Dim j As Integer
                    Dim x() As String = Session("FieldDef")
                    For j = 0 To x.GetUpperBound(0) - 1
                        crParameterDiscreteValue.Value = x(j)
                        crParameterFieldDefinition.CurrentValues.Add(crParameterDiscreteValue)
                    Next
                End If
                Session.Remove("FieldDef")
                i = i + 1
            End If
        Next
    I have also tried loading the values into a ParameterValues object and then using ParameterFieldDefinition.ApplyCurrentValues on it, which has been working fine for all of my single value inputs, but using that throws an error about a type mismatch. Any help at all would be appreciated.

    There are a few samples to look at here:
    https://wiki.sdn.sap.com/wiki/display/BOBJ/CrystalReportsfor.NETSDK+Samples
    Vbnet_win_paramengine.zip, vbnet_win_multirangeparam.zip and vbnet_win_rangeparameters.zip may be good
    Also, [this|http://www.sdn.sap.com/irj/boc/go/portal/prtroot/docs/library/uuid/2081b4d9-6864-2b10-f49d-918baefc7a23?quicklink=index&overridelayout=true] article has great info.
    This is all assuming you are on SP3 for CR2008:
    https://smpdl.sap-ag.de/~sapidp/012002523100009989492010E/cr2008_sp3_fullbuild.zip
    SP 3 msi     
    https://smpdl.sap-ag.de/~sapidp/012002523100007123592010E/cr2008sp3_redist.zip
    SP 3 msm     
    https://smpdl.sap-ag.de/~sapidp/012002523100007123582010E/cr2008sp3_mm.zip
    Ludek

  • Upload Profile Values

    Hi Folks,
    I would like to know how to upload profile values in SAP.
    In our current project due to time zone problem half of the profile values are stored in one valueday and the rest of the values are stored for the next valueday.
    Thanks,
    Imran

    Hi Imran,
    You can upload profile values through transaction code EEDM01.
    However, through the above transaction code  you can only upload on a one to one basis and not mass.
    If you want to perform a mass upload of profile values you need to develop a customise program using the FM BAPI_ISUPROFILE_UPLOAD.
    Hope it helps...
    Thanks,
    Amlan
    Edited by: Amlan B on Aug 11, 2010 10:09 PM

  • Multi-Valued Properties in XML Forms

    Hello,
    Can anyone tell me how to select multiple values for multi-valued properties in an XML Forms. It seems that the combo box only allows you to select one value.
    Thanks,
    Chris.

    Hi Chris,
    nice to hear, that you're implementing my way of solving this multi value issue. And much nicer to hear, that it seems to work for you, too!
    You can not write back your multi value properties from XML form. Thats for sure. You can think of:
    1. Synchronize the value of your text field property with the value of the multi value propery whenever you store the document. This could be done using the event "property set".
    <a href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/5d0ab890-0201-0010-849d-98d70bd1d5f0">See: KM Events</a>
    2. Overwrite the content of your multi value property at runtime, depending on the value of the single value property which holds the csv. Do this by using a Repository Filter. <a href="https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/70ee3a57-0701-0010-3e9a-ddae7e4e0521">See: RepositoryFilter</a>
    3. Forget about the multi value property and make the text field property indexable. This should work, too.
    All three options should work!
    HTH,
    Carsten

  • Multi value refiners -- Remove Other Value

    While using Multi value refiners (using check boxes)  is there any way we can remove Other Value refiner.
    Thanks in advance.

    Hi,
    You can write some CSS to hide this control, or use Javascript to remove it.
    If you are looking for a more standard solution, you can create a custom refiner control template.
    Check this blog series - http://www.eliostruyf.com/part-1-create-first-search-refiner-control-template/
    Ram Prasad Meenavalli | MCITP | MCTS SharePoint | MCPD SharePoint | http://www.spdeveloper.co.in

  • How can I get all the values of a String array profile property using javascript?

    I am trying to build functionality into our site that records all products added to the basket against a user's profile.
    I have so far been able to store the product codes against the profile as a property using Ajax:
           var dataString = ":formid=addProduct&:formstart=/apps/thread/templates/page_product/jcr:content/par/produc t/formstart&:redirect=/content/thread/en/user/cart.html&productId=151515:profile="+profile ;
                         $.ajax({ 
                type: "POST", 
                url: "/content/women/evening/dresses/l-k-bennett-davinadress.html", 
                data: dataString, 
                success: function(data) { 
    In this example I have hardcoded a product ID of 151515.
    In order to save the property as a multi string field you simply replace &productId=151515 with &productId=151515&productId=131313&productId=141414 or as many extra values as you want to build into that string. This stores a productId property against a user profile.
    The issue comes from calling that data back. Using var value = CQ_Analytics.ProfileDataMgr.getProperty("productId") I can get the first value of this array (or the single value if only one is stored).
    However there does not seem to be a way to get any of the other stored values in the array using getProperty. Does anyone know how I can achieve this?

    Hi,
    Don't think that's possible. Even if it were, you wouldn't be able to use/display BOOLEAN type in SQL.
    If you just aim to see what they are, you could do something like this
    select text
      from all_source
    where owner = 'SYS'
       and name = 'DBMS_DB_VERSION'
       and type = 'PACKAGE';Or even
    select dbms_metadata.get_ddl('PACKAGE', 'DBMS_DB_VERSION', 'SYS') from dual;My version is:
    SQL> select * from v$version where rownum = 1;
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    1 row selectedIn 11g you also have [PL/SCOPE|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_plscope.htm#ADFNS02203] which might help you even more.
    Regards
    Peter

  • Passing value to multi value parameter from SSIS using Report server webservice

    Hi
    I am triggering SSRS report from SSIS(Script task). I am passing parameter values from SSIS package.
    So far working fine. Now, I have a report which has 2 parameters. One is single value parameter and the other is multi value parameter.
    No issue assigning value to single value parameter. But how can I pass multi value to multi value parameter?
    My code as below
    ReportExecutionService rs = new ReportExecutionService()
    rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
    rs.Url = _webserviceURL;
    rs.LoadReport(_reportPath, null);
    ParameterValue[] paramval = new ParameterValue[2];
                            paramval[0] = new ParameterValue();
                            paramval[0].Name = "CountryCode";
                            paramval[0].Value = _countryNames;
                            **paramval[1] = new ParameterValue();
                            paramval[1].Name = "BusinessCode";
                            paramval[1].Value = _businessCode;****
                            rs.SetExecutionParameters(paramval, "en-us");
    I am not sure how to pass value to BusinessCode(Multi value parameter)

    Hi Rajkm,
    In order to pass a multi-value parameter through the Reporting Services Web services, you need to define the same numbers of ParameterValue objects as the number of the values of the multi-value parameter being past into the report. The Name property
    of these ParameterValue objects must be specified same to the parameter name.
    I found a good FAQ article for this scenario:
    How do I pass a multi-value parameter into a report with Reporting Services Web service API?:
    http://blogs.msdn.com/b/sqlforum/archive/2010/12/21/faq-how-do-i-pass-a-multi-value-parameter-into-a-report-with-sql-server-reporting-services-ssrs-web-services-api.aspx
    Hope this helps.
    Elvis Long
    TechNet Community Support

  • Result Type Condition for Multi value Manage Property not working

    Hi All,
    I have created one template & I wanted to show this template on particular condition. So I created the result type. The Managed property (MP) that I used, I have verified its attributes all attributes are selected and its type is Multi value. I am trying
    to apply the "Show fewer conditions" and some how the value not matched.
    I have checked MP ; it has all the values but some how the template not called. When I removed this condition it working and when choose other MP other then Multi valued. It is working as expected.
     Please let me know if i miss something here. 
    PS: I have checked each option from the Query drop down like "Equals any of" and "Contains any of" not working in case of multi value attribute. Please help.
    I have explain this issue more details in this post : http://sharepointfordeveloper.blogspot.com/2015/02/sharepoint-search-2013-result-type-with.html
    Regards,
    Basant Pandey
    http://sharepointfordeveloper.blogspot.com

    Update on above mentioned issue.
    I have verified the same at my end. So I come to this conclusion this is product issue. Either need to raise the ticket to Microsoft related to this issue.
    Regards,
    Basant Pandey
    http://sharepointfordeveloper.blogspot.com

  • ECC6.0 code download/upload with unicode

    Hi, we have a need for on-going parallel code maintenance of 2 separate development instances.  In end effect we need to manually synchronize two development instances for a period of time.  We have before in the past used custom programs and some of the standard SAP utilities provided.  However I'd be surprised if there isn't a more comprehensive utility supplied by SAP by now for this purpose.  By now I mean with release ECC6.0 with unicode active.  Does anyone out there know of a utility that can download any program(WebDynpro, BSP, R/3 dynpro, report, program, function module, class, etc with all relevant textpools and documentation) to a file so that it can be uploaded in its entirety without great effort?  We currently have a custom program which downloads/uploads ABAP source and text but it only works with standard executable r/3 programs.
    Thanks in advance,
    Kevin

    Here is the link for the google code site where you can download Saplink.
    http://code.google.com/p/saplink/
    Here is the direct link to the saplink installation zip file.  There should be some instructions within.
    http://saplink.googlecode.com/files/SAPlink_install-0.1.3.zip
    Once you have the base installation installed, you can then start adding plugins for other development objects.  The plugins have their own site.
    http://code.google.com/p/saplink/wiki/pluginList
    REgards,
    Rich Heilman

  • Useful Code of the Day:  Multipart Form File Upload

    So, you want to upload files to your web server, do ya? Well, I've seen this topic posted a few times in the last month or so and many of the response I've seen here haven't included definitive answers. Of course, the actual problems vary, but ultimately, a bunch of people want to do file upload from an applet or application to an existing file upload script (CGI, PHP, JSP, etc.) on a web server. And invariably, there are problems with formatting the HTTP request to get things working.
    Well, I had a need to do the same thing. I realize there are other solutions out there, such as some sample code that comes with Jakarta Commons Upload. But since we all like reusable code, and we also all seem to like reinventing wheels, here's my go at it: MultiPartFormOutputStream!
    MultiPartFormOutputStream is a specialized OutputStream-like class. You create your URLConnection to the server (a static method included can do this for a URL for you, as some of the settings, doInput and doOutput specifically, seem to confuse people). Then get the OutputStream from it and create a boundary string (a static method to create one is provided as well) and pass them to the constructor. Now you have a MultiPartFormOutputStream which you can use to write form fields like text fields, checkboxes, etc., as well as write file data (from Files, InputStreams or raw bytes).
    There are some convenience methods for writing primative type values as well as strings, but any higher level objects (aside from Files or InputStreams) aren't supported. (You can always serialize and pass the raw bytes.)
    Sample usage code is below. Also, any recommendations for improvement are requested. The code was tested with the Jakarta Struts.
    import java.io.*;
    import java.net.*;
    * <code>MultiPartFormOutputStream</code> is used to write
    * "multipart/form-data" to a <code>java.net.URLConnection</code> for
    * POSTing.  This is primarily for file uploading to HTTP servers. 
    * @since  JDK1.3
    public class MultiPartFormOutputStream {
          * The line end characters. 
         private static final String NEWLINE = "\r\n";
          * The boundary prefix. 
         private static final String PREFIX = "--";
          * The output stream to write to. 
         private DataOutputStream out = null;
          * The multipart boundary string. 
         private String boundary = null;
          * Creates a new <code>MultiPartFormOutputStream</code> object using
          * the specified output stream and boundary.  The boundary is required
          * to be created before using this method, as described in the
          * description for the <code>getContentType(String)</code> method. 
          * The boundary is only checked for <code>null</code> or empty string,
          * but it is recommended to be at least 6 characters.  (Or use the
          * static createBoundary() method to create one.)
          * @param  os        the output stream
          * @param  boundary  the boundary
          * @see  #createBoundary()
          * @see  #getContentType(String)
         public MultiPartFormOutputStream(OutputStream os, String boundary) {
              if(os == null) {
                   throw new IllegalArgumentException("Output stream is required.");
              if(boundary == null || boundary.length() == 0) {
                   throw new IllegalArgumentException("Boundary stream is required.");
              this.out = new DataOutputStream(os);
              this.boundary = boundary;
          * Writes an boolean field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, boolean value)
                   throws java.io.IOException {
              writeField(name, new Boolean(value).toString());
          * Writes an double field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, double value)
                   throws java.io.IOException {
              writeField(name, Double.toString(value));
          * Writes an float field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, float value)
                   throws java.io.IOException {
              writeField(name, Float.toString(value));
          * Writes an long field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, long value)
                   throws java.io.IOException {
              writeField(name, Long.toString(value));
          * Writes an int field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, int value)
                   throws java.io.IOException {
              writeField(name, Integer.toString(value));
          * Writes an short field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, short value)
                   throws java.io.IOException {
              writeField(name, Short.toString(value));
          * Writes an char field value. 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, char value)
                   throws java.io.IOException {
              writeField(name, new Character(value).toString());
          * Writes an string field value.  If the value is null, an empty string
          * is sent (""). 
          * @param  name   the field name (required)
          * @param  value  the field value
          * @throws  java.io.IOException  on input/output errors
         public void writeField(String name, String value)
                   throws java.io.IOException {
              if(name == null) {
                   throw new IllegalArgumentException("Name cannot be null or empty.");
              if(value == null) {
                   value = "";
              --boundary\r\n
              Content-Disposition: form-data; name="<fieldName>"\r\n
              \r\n
              <value>\r\n
              // write boundary
              out.writeBytes(PREFIX);
              out.writeBytes(boundary);
              out.writeBytes(NEWLINE);
              // write content header
              out.writeBytes("Content-Disposition: form-data; name=\"" + name + "\"");
              out.writeBytes(NEWLINE);
              out.writeBytes(NEWLINE);
              // write content
              out.writeBytes(value);
              out.writeBytes(NEWLINE);
              out.flush();
          * Writes a file's contents.  If the file is null, does not exists, or
          * is a directory, a <code>java.lang.IllegalArgumentException</code>
          * will be thrown. 
          * @param  name      the field name
          * @param  mimeType  the file content type (optional, recommended)
          * @param  file      the file (the file must exist)
          * @throws  java.io.IOException  on input/output errors
         public void writeFile(String name, String mimeType, File file)
                   throws java.io.IOException {
              if(file == null) {
                   throw new IllegalArgumentException("File cannot be null.");
              if(!file.exists()) {
                   throw new IllegalArgumentException("File does not exist.");
              if(file.isDirectory()) {
                   throw new IllegalArgumentException("File cannot be a directory.");
              writeFile(name, mimeType, file.getCanonicalPath(), new FileInputStream(file));
          * Writes a input stream's contents.  If the input stream is null, a
          * <code>java.lang.IllegalArgumentException</code> will be thrown. 
          * @param  name      the field name
          * @param  mimeType  the file content type (optional, recommended)
          * @param  fileName  the file name (required)
          * @param  is        the input stream
          * @throws  java.io.IOException  on input/output errors
         public void writeFile(String name, String mimeType,
                   String fileName, InputStream is)
                   throws java.io.IOException {
              if(is == null) {
                   throw new IllegalArgumentException("Input stream cannot be null.");
              if(fileName == null || fileName.length() == 0) {
                   throw new IllegalArgumentException("File name cannot be null or empty.");
              --boundary\r\n
              Content-Disposition: form-data; name="<fieldName>"; filename="<filename>"\r\n
              Content-Type: <mime-type>\r\n
              \r\n
              <file-data>\r\n
              // write boundary
              out.writeBytes(PREFIX);
              out.writeBytes(boundary);
              out.writeBytes(NEWLINE);
              // write content header
              out.writeBytes("Content-Disposition: form-data; name=\"" + name +
                   "\"; filename=\"" + fileName + "\"");
              out.writeBytes(NEWLINE);
              if(mimeType != null) {
                   out.writeBytes("Content-Type: " + mimeType);
                   out.writeBytes(NEWLINE);
              out.writeBytes(NEWLINE);
              // write content
              byte[] data = new byte[1024];
              int r = 0;
              while((r = is.read(data, 0, data.length)) != -1) {
                   out.write(data, 0, r);
              // close input stream, but ignore any possible exception for it
              try {
                   is.close();
              } catch(Exception e) {}
              out.writeBytes(NEWLINE);
              out.flush();
          * Writes the given bytes.  The bytes are assumed to be the contents
          * of a file, and will be sent as such.  If the data is null, a
          * <code>java.lang.IllegalArgumentException</code> will be thrown. 
          * @param  name      the field name
          * @param  mimeType  the file content type (optional, recommended)
          * @param  fileName  the file name (required)
          * @param  data      the file data
          * @throws  java.io.IOException  on input/output errors
         public void writeFile(String name, String mimeType,
                   String fileName, byte[] data)
                   throws java.io.IOException {
              if(data == null) {
                   throw new IllegalArgumentException("Data cannot be null.");
              if(fileName == null || fileName.length() == 0) {
                   throw new IllegalArgumentException("File name cannot be null or empty.");
              --boundary\r\n
              Content-Disposition: form-data; name="<fieldName>"; filename="<filename>"\r\n
              Content-Type: <mime-type>\r\n
              \r\n
              <file-data>\r\n
              // write boundary
              out.writeBytes(PREFIX);
              out.writeBytes(boundary);
              out.writeBytes(NEWLINE);
              // write content header
              out.writeBytes("Content-Disposition: form-data; name=\"" + name +
                   "\"; filename=\"" + fileName + "\"");
              out.writeBytes(NEWLINE);
              if(mimeType != null) {
                   out.writeBytes("Content-Type: " + mimeType);
                   out.writeBytes(NEWLINE);
              out.writeBytes(NEWLINE);
              // write content
              out.write(data, 0, data.length);
              out.writeBytes(NEWLINE);
              out.flush();
          * Flushes the stream.  Actually, this method does nothing, as the only
          * write methods are highly specialized and automatically flush. 
          * @throws  java.io.IOException  on input/output errors
         public void flush() throws java.io.IOException {
              // out.flush();
          * Closes the stream.  <br />
          * <br />
          * <b>NOTE:</b> This method <b>MUST</b> be called to finalize the
          * multipart stream.
          * @throws  java.io.IOException  on input/output errors
         public void close() throws java.io.IOException {
              // write final boundary
              out.writeBytes(PREFIX);
              out.writeBytes(boundary);
              out.writeBytes(PREFIX);
              out.writeBytes(NEWLINE);
              out.flush();
              out.close();
          * Gets the multipart boundary string being used by this stream. 
          * @return  the boundary
         public String getBoundary() {
              return this.boundary;
          * Creates a new <code>java.net.URLConnection</code> object from the
          * specified <code>java.net.URL</code>.  This is a convenience method
          * which will set the <code>doInput</code>, <code>doOutput</code>,
          * <code>useCaches</code> and <code>defaultUseCaches</code> fields to
          * the appropriate settings in the correct order. 
          * @return  a <code>java.net.URLConnection</code> object for the URL
          * @throws  java.io.IOException  on input/output errors
         public static URLConnection createConnection(URL url)
                   throws java.io.IOException {
              URLConnection urlConn = url.openConnection();
              if(urlConn instanceof HttpURLConnection) {
                   HttpURLConnection httpConn = (HttpURLConnection)urlConn;
                   httpConn.setRequestMethod("POST");
              urlConn.setDoInput(true);
              urlConn.setDoOutput(true);
              urlConn.setUseCaches(false);
              urlConn.setDefaultUseCaches(false);
              return urlConn;
          * Creates a multipart boundary string by concatenating 20 hyphens (-)
          * and the hexadecimal (base-16) representation of the current time in
          * milliseconds. 
          * @return  a multipart boundary string
          * @see  #getContentType(String)
         public static String createBoundary() {
              return "--------------------" +
                   Long.toString(System.currentTimeMillis(), 16);
          * Gets the content type string suitable for the
          * <code>java.net.URLConnection</code> which includes the multipart
          * boundary string.  <br />
          * <br />
          * This method is static because, due to the nature of the
          * <code>java.net.URLConnection</code> class, once the output stream
          * for the connection is acquired, it's too late to set the content
          * type (or any other request parameter).  So one has to create a
          * multipart boundary string first before using this class, such as
          * with the <code>createBoundary()</code> method. 
          * @param  boundary  the boundary string
          * @return  the content type string
          * @see  #createBoundary()
         public static String getContentType(String boundary) {
              return "multipart/form-data; boundary=" + boundary;
    }Usage: (try/catch left out to shorten the post a bit)
    URL url = new URL("http://www.domain.com/webems/upload.do");
    // create a boundary string
    String boundary = MultiPartFormOutputStream.createBoundary();
    URLConnection urlConn = MultiPartFormOutputStream.createConnection(url);
    urlConn.setRequestProperty("Accept", "*/*");
    urlConn.setRequestProperty("Content-Type",
         MultiPartFormOutputStream.getContentType(boundary));
    // set some other request headers...
    urlConn.setRequestProperty("Connection", "Keep-Alive");
    urlConn.setRequestProperty("Cache-Control", "no-cache");
    // no need to connect cuz getOutputStream() does it
    MultiPartFormOutputStream out =
         new MultiPartFormOutputStream(urlConn.getOutputStream(), boundary);
    // write a text field element
    out.writeField("myText", "text field text");
    // upload a file
    out.writeFile("myFile", "text/plain", new File("C:\\test.txt"));
    // can also write bytes directly
    //out.writeFile("myFile", "text/plain", "C:\\test.txt",
    //     "This is some file text.".getBytes("ASCII"));
    out.close();
    // read response from server
    BufferedReader in = new BufferedReader(
         new InputStreamReader(urlConn.getInputStream()));
    String line = "";
    while((line = in.readLine()) != null) {
          System.out.println(line);
    in.close();------
    "Useful Code of the Day" is supplied by the person who posted this message. This code is not guaranteed by any warranty whatsoever. The code is free to use and modify as you see fit. The code was tested and worked for the author. If anyone else has some useful code, feel free to post it under this heading.

    I have a weird problem here. I'm using the Java POST (slightly altered for my purposes) mechanism but the receiving script doesn't receive any form variables (neither files nor regular form fields). If I try using the same receiving script with a regular upload form, it works. Because I've been pulling my hair out, I even went so far as to analyze the ip-packets. I can see that the file is actually sent through the Java POST mecahnism. Anybody any ideas. Here's the ip-packet of the failing upload:
    ----- Hypertext Transfer Protocol -----
    HTTP: POST /fotoxs/upload.cfm HTTP/1.1
    HTTP: Connection: Keep-Alive
    HTTP: Content-Type: multipart/form-data; boundary=-----------------------------fb2649be18
    HTTP: User-Agent: Mozilla/4.7 [en] (WinNT; U)
    HTTP: Accept-Language: en-us
    HTTP: Accept-Encoding: gzip, deflate
    HTTP: Accept: image/gif, image/jpeg, image/pjpeg, */*
    HTTP: CACHE-CONTROL: no-cache
    HTTP: Host: newmarc
    HTTP: Content-Length: 15511
    ----- Hypertext Transfer Protocol -----
    HTTP: -----------------------------fb2649be18
    HTTP: Content-Disposition: form-data; name="uploadFile"; filename="out.jpg"
    HTTP: Content-Type: image/jpeg
    HTTP: Data
    ....[data packets]
    The one that works (from the regular post) is as follows:
    ----- Hypertext Transfer Protocol -----
    HTTP: POST /fotoxs/upload.cfm HTTP/1.1
    HTTP: Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-gsarcade-launch, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
    HTTP: Referer: http://localhost:8500/fotoxs/test.cfm
    HTTP: Accept-Language: nl
    HTTP: Content-Type: multipart/form-data; boundary=---------------------------7d41961f201c0
    HTTP: Accept-Encoding: gzip, deflate
    HTTP: User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
    HTTP: Host: newmarc
    HTTP: Content-Length: 59022
    HTTP: Connection: Keep-Alive
    HTTP: Cache-Control: no-cache
    ----- Hypertext Transfer Protocol -----
    HTTP: -----------------------------7d41961f201c0
    HTTP: Content-Disposition: form-data; name="FiletoUpload"; filename="D:\My Documents\My Pictures\fotomarc.jpg"
    HTTP: Content-Type: image/pjpeg
    HTTP: Data
    ----- Hypertext Transfer Protocol -----
    HTTP: HTTP/1.1 100 Continue
    HTTP: Server: Microsoft-IIS/5.0
    HTTP: Date: Sun, 07 Mar 2004 17:14:41 GMT
    ....[data packets]
    One detail worth mentioning is that I don't read a file from harddisk, I'm streaming it directly to the connection outputstream from an image compression utility. But I can see the data in the ip-packets, and even if that somehow didn't work right, it doesn't explaing the fact that the receiving scripts reports no form fields whatsoever.
    Thanks,
    Marc

Maybe you are looking for

  • How do you get a sim card for an LTE iPad?

    How and where do you get a mini sim card for a new iPad? Does it work with the iPhone? I'm just saying this because I got a new iPad as a gift and it doesn't have a sim card, so how do I get one? And what plan does it come with?

  • Problem with logical database

    Hello experts, i want to mix the data of the two transactions CjI3 CjI5 into one table. Both Transactions or programs use LDB psj. So i want to use one perform for each LDB call. I want to call the LDB with the FM LDB_PROCESS. I want to get the data

  • I am new to workflow and I have and issue

    Hi Experts, I am very new to workflow and Ive got an issue which I need know where to start with. I am working with an application whose UI is Java and back end is SAP. When a sales order is created in the UI this creates a order record in SAP and tr

  • How to return hp touchsmart tx2-1340ea laptop to factory settings

    I have a hp touchsmart  tx2-1340ea laptop and want to return it to its origional factory settings. Can anyone help? Thank You!

  • How to download SIS file

    I am using N95, I can't download SIS installer with the build in browser as well as in Opera, the file opens in text editor instead. Message Edited by lotech on 18-Jan-2009 03:43 AM