Welcome to Dream.In.Code
Become an Expert!

Join 149,598 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,906 people online right now. Registration is fast and FREE... Join Now!




how to access a file at the server which is posted to it by client

 
Reply to this topicStart new topic

how to access a file at the server which is posted to it by client

sucharitha
7 Oct, 2007 - 09:30 PM
Post #1

New D.I.C Head
*

Joined: 7 Oct, 2007
Posts: 4


My Contributions
hey,
can any one please help regarding accessing a posted file at the server.
my code goes like this:

CLIENT:

CODE

      File input = new File("XMLFile1.xml");                         
            RequestEntity entity = new FileRequestEntity(input);
           PostMethod post = new PostMethod(url);
            post.setRequestEntity(entity);             
            HttpClient httpclient = new HttpClient();
          
            try
            {
                int result = httpclient.executeMethod(post);
                if (result >=200 && result <=210 ) {
                System.out.println("Request Timed out");
                     System.err.println("Method Failed:"post.getStatusLine()+ post.getStatusText());}              
                System.out.println("Response status code: "+result);                              
                System.out.println(post.getResponseBodyAsString());
            }
            catch(Exception e)
            {
                System.out.println("Response body: ");
            }
            finally
            {
                post.releaseConnection();
            }


SERVER:

CODE

             Dim c, i As Integer
        Dim objFile As HttpPostedFile
        c = Request.Files.Count
        For i = 0 To c - 1
            objFile = Request.Files(0)
            objFile.SaveAs("c:\test2\" + objFile.FileName)
        Next
        Response.Write©


the problem with this code is, i'm getting a response code as 200 when the file is posted.
but at the server, count variable c is showing 0(i.e Request.Files.Count=0).the file is not recieved by the server.
is this code correct? then why the count variable is showing 0? please help me this.

thank u in advance

*Always use code blocks smile.gif

This post has been edited by PsychoCoder: 8 Oct, 2007 - 03:46 AM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: How To Access A File At The Server Which Is Posted To It By Client
8 Oct, 2007 - 03:56 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,482



Thanked: 161 times
Dream Kudos: 9050
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Are you using jsp? HttpClient isn't a .Net Object in either VB.Net or C#
User is offlineProfile CardPM
+Quote Post

serializer
RE: How To Access A File At The Server Which Is Posted To It By Client
8 Oct, 2007 - 10:48 AM
Post #3

D.I.C Head
**

Joined: 25 Jun, 2007
Posts: 108


My Contributions

I'm not at all sure about the HttpClient but I can see one problem with your server code:

CODE

            objFile = Request.Files(0)


Should be:

CODE

            objFile = Request.Files(i)


I assume this is why you're running the loop? This won't cause a problem of course unless you're sending more than one file!
User is offlineProfile CardPM
+Quote Post

sucharitha
RE: How To Access A File At The Server Which Is Posted To It By Client
11 Oct, 2007 - 08:38 PM
Post #4

New D.I.C Head
*

Joined: 7 Oct, 2007
Posts: 4


My Contributions
QUOTE(serializer @ 8 Oct, 2007 - 11:48 AM) *

I'm not at all sure about the HttpClient but I can see one problem with your server code:

CODE

            objFile = Request.Files(0)


Should be:

CODE

            objFile = Request.Files(i)


I assume this is why you're running the loop? This won't cause a problem of course unless you're sending more than one file!


User is offlineProfile CardPM
+Quote Post

sucharitha
RE: How To Access A File At The Server Which Is Posted To It By Client
13 Oct, 2007 - 08:09 AM
Post #5

New D.I.C Head
*

Joined: 7 Oct, 2007
Posts: 4


My Contributions
QUOTE(sucharitha @ 11 Oct, 2007 - 09:38 PM) *

QUOTE(serializer @ 8 Oct, 2007 - 11:48 AM) *

I'm not at all sure about the HttpClient but I can see one problem with your server code:

CODE

            objFile = Request.Files(0)


Should be:

CODE

            objFile = Request.Files(i)


I assume this is why you're running the loop? This won't cause a problem of course unless you're sending more than one file!



User is offlineProfile CardPM
+Quote Post

sucharitha
RE: How To Access A File At The Server Which Is Posted To It By Client
1 Nov, 2007 - 10:19 PM
Post #6

New D.I.C Head
*

Joined: 7 Oct, 2007
Posts: 4


My Contributions
hey...

ANy one plzzz help with this problem???????
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:39PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month