uploading docx,doc and pdf file to sharepoint onli

2019-04-14 16:12发布

I am developing an android app to remotely access sharepoint online.I am able to upload files using http put method and view them but i am not able to open them.I feel i am not specifying the proper content type.Here's my code:

try {       
    File sdcard = Environment.getExternalStorageDirectory();

    //Get the text file
    File file = new File(sdcard, "gps.doc");

    FileInputStream fIn = new FileInputStream(file);
    BufferedReader myReader = new BufferedReader(
            new InputStreamReader(fIn));
    String aDataRow = "";
    String aBuffer = "";
    while ((aDataRow = myReader.readLine()) != null) {
        aBuffer += aDataRow + "\n";
    }

    System.out.println(aBuffer + "content of the file");

    HttpPut httpupld = new HttpPut("http://mysite.sharepoint.com/Sites/Documents/gps.doc");


    StringEntity entity1 = new StringEntity(aBuffer, "HTTP.UTF_8");
    httpDel.setEntity(entity1);


    System.out.println(title);
    HttpResponse rsp = http2.execute(httpupld);
    respcode=rsp.getStatusLine().getStatusCode();
    System.out.println(respcode);

} catch (Exception e) {
    Log.e("Error: ", e.getMessage());
}

Any help is appreciated.Thankyou

1条回答
小情绪 Triste *
2楼-- · 2019-04-14 16:32

You can't open (but view) doc in Office Web Apps either on SharePoint Online or if you have it installed on-premises.

Convert your office documents to the office 2007/2010 standards before uploading them, that's docx, xlsx, pptx ...

查看更多
登录 后发表回答