Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6833511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:59:15+00:00 2026-05-26T22:59:15+00:00

I have problem in uploading .doc file to .Net WCF from my Android app.

  • 0

I have problem in uploading .doc file to .Net WCF from my Android app. I am able to send file but it is not supported on WCF end.
Here is my method for uploading:

protected void checkinmethod(String rid) throws Exception {

         File SDCardRoot = Environment.getExternalStorageDirectory();
         //create a new file, specifying the path, and the filename
       //which we want to save the file as.
         File file = new File(SDCardRoot, rid+".doc"); 
         InputStream in = new FileInputStream(file);

         byte[] bytearray=new byte[(int) file.length()]; 

         int ab=0;
         do
         {
             ab=in.read(bytearray, 0, bytearray.length);

         } while(ab>0);



        InputStream mystream= new ByteArrayInputStream(bytearray);
         InputStreamEntity se=new InputStreamEntity(mystream, 10000);

         HttpPost request = new HttpPost("http://10.66.52.247/tutorwcf/Service.svc/Service/updateMyDoc1");
         request.setHeader("Accept", "application/json");
         request.setHeader("Content-type", "application/msword");
        request.setEntity(se);





         try {



             DefaultHttpClient httpClient = new DefaultHttpClient();

             HttpResponse response = httpClient.execute(request);

             HttpEntity responseEntity = response.getEntity();

             // Read response data into buffer
             char[] buffer = new char[(int)responseEntity.getContentLength()];
             InputStream stream = responseEntity.getContent();
             InputStreamReader reader = new InputStreamReader(stream);
             reader.read(buffer);
             stream.close();
             statuss.setText(new String(buffer));

         //
         }
         catch (Exception e) {
            // TODO: handle exception
            Log.e("hi", "exception is", e);
             statuss.setText("exception");
        }
    }

here is .net code:

FileStream fileToupload = new FileStream("D:\\myfile.doc", FileMode.Create, FileAccess.Write);

byte[] bytearray = new byte[10000];
int bytesRead, totalBytesRead = 0;
do
{
bytesRead = mystream.Read(bytearray, 0, bytearray.Length);
totalBytesRead += bytesRead;
} while (bytesRead > 0);

fileToupload.Write(bytearray, 0, bytearray.Length);
fileToupload.Close();
fileToupload.Dispose();
return "success";

}

Please send links or code or any thing.

If you don’t have idea about this please rank up this question..
thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:59:16+00:00Added an answer on May 26, 2026 at 10:59 pm
    public void checkinstream(String rid, String filename ) throws IOException
            { 
                      URL url=null;
                    HttpURLConnection conn = null;
                        DataOutputStream dos = null;
                        DataInputStream inStream = null;
                        String existingFileName= null;
    
                         existingFileName=    "/mnt/sdcard/"+rid+".doc";
                        int bytesRead, bytesAvailable, bufferSize;
                        byte[] buffer;
                        int maxBufferSize = Integer.MAX_VALUE;
                        String responseFromServer = "";
    
    
                     url = new URL("http://10.66.51.241/mywcf/Service.svc/Service/uploadMyDoc");               
    
                        try
                        {
                         //------------------ CLIENT REQUEST
                        FileInputStream fileInputStream = new FileInputStream(new File(existingFileName) );
    
                         // Open a HTTP connection to the URL
                         conn = (HttpURLConnection) url.openConnection();
                         // Allow Inputs
                         conn.setDoInput(true);
                         // Allow Outputs
                         conn.setDoOutput(true);
                         // Don't use a cached copy.
                         conn.setUseCaches(false);
                         // Use a post method.
                         conn.setRequestMethod("POST");
                         conn.setRequestProperty("Connection", "Keep-Alive");
                         conn.setRequestProperty("Content-Type", "application/stream");
                         dos = new DataOutputStream( conn.getOutputStream() );
                      //   dos.writeBytes(twoHyphens + boundary + lineEnd);
                         //dos.writeBytes("Content-Disposition: form-data; name=\"uploadedfile\";filename=\"" + existingFileName + "\"" + lineEnd);
                       //  dos.writeBytes(lineEnd);
                         // create a buffer of maximum size
                         bytesAvailable = fileInputStream.available();
                         bufferSize = Math.min(bytesAvailable, maxBufferSize);
                         buffer = new byte[bufferSize];
                         // read file and write it into form...
                         bytesRead = fileInputStream.read(buffer, 0, bufferSize);
                         while (bytesRead > 0)
                         {
                          dos.write(buffer, 0, bufferSize);
                          bytesAvailable = fileInputStream.available();
                          bufferSize = Math.min(bytesAvailable, maxBufferSize);
                          bytesRead = fileInputStream.read(buffer, 0, bufferSize);
    
                         }
                         // send multipart form data necesssary after file data...
                         dos.writeBytes(lineEnd);
    
    
                         // close streams
                         Log.e("Debug",twoHyphens + boundary + twoHyphens + lineEnd);
                         fileInputStream.close();
                         dos.flush();
                         dos.close();
                        }
                        catch (MalformedURLException ex)
                        {
                             Log.e("Debug", "error: " + ex.getMessage(), ex);
                        }
                        catch (IOException ioe)
                        {
                             Log.e("Debug", "error: " + ioe.getMessage(), ioe);
                        }
                        //------------------ read the SERVER RESPONSE
                        try {
                              inStream = new DataInputStream ( conn.getInputStream() );
                              String str;
    
                              while (( str = inStream.readLine()) != null)
                              {
                                   Log.e("Debug","Server Response "+str);
                                   statuss.setText(str);
                              }
                              inStream.close();
    
                        }
                        catch (IOException ioex){
                             Log.e("Debug", "error: " + ioex.getMessage(), ioex);
                        }
    
    
            }
    

    On the .net end create a wcf method which receives stream.
    Thanks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have same problem. other files doc, xls uploads fine. but pdf uploading gives
I have a problem with uploading file in asp.net mvc 2. My controller function's
all. I have a problem with uploading of the file in Silverlight application. Here
I have a problem uploading file to a network shared folder. I can connect
I have a problem with uploading a django app to dotcloud. I'm using the
I have a problem of upgrading python from 2.4 to 2.6: I have CentOS
I have problem with starting processes in impersonated context in ASP.NET 2.0. I am
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I am using Cakephp as my framework. I have a problem in uploading my
I have a .NET 3.5 website that is uploading files to a SQL Server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.