Saturday, August 23, 2014

How to download file from Sharepoint Site through Android programming.

 File file = new File(Environment.getExternalStorageDirectory() + "/" + "NCR-MFS" + "/" + "newfilename.xls");
        System.out.println(Environment.getExternalStorageDirectory() + "/" + "NCR-MFS" + "/" + "Rajeev1.xls");

DefaultHttpClient httpclient = new DefaultHttpClient();

        // register ntlm auth scheme
        httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
        System.out.println("3:"+password);
        httpclient.getCredentialsProvider().setCredentials(
                // Limit the credentials only to the specified domain and port
                new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                // Specify credentials, most of the time only user/pass is needed
                new NTCredentials(username, password, "", "corp")
        );


        HttpUriRequest httpget = new HttpGet(sharepoint Url);
        
        

        try
        {

        HttpResponse response = httpclient.execute(httpget);
        
       

        HttpEntity entity = response.getEntity();
        InputStream is = entity.getContent();
        BufferedInputStream bis = new BufferedInputStream(is);

        /*
         * Read bytes to the Buffer until there is nothing more to read(-1).
         */
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }
        
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baf.toByteArray());
        fos.close();
        

No comments:

Post a Comment