Address parameter in WebClient.UploadFile?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • linn

    #1

    Address parameter in WebClient.UploadFile?

    The 'Address' parameter in the WebClient.Uploa dFile usually comes in
    the form of ie. http://server/Upload_File.aspx

    Hence my question, what is exactly the content of this
    Upload_File.asp x? Am i supposed to create this file with some specific
    codes?

    Can't seems to get this method working for me in framework 2.0..

    Thanks for any help.

  • vbnetdev

    #2
    Re: Address parameter in WebClient.Uploa dFile?

    Play with this.....

    Friend Function UploadFile(ByVa l SourceLocation As String, ByVal
    DestinationLoca tion As String, ByRef ProgressBar As
    System.Windows. Forms.ProgressB ar) As Boolean
    Dim StartTime As DateTime = DateTime.Now()
    Dim Response As String = Nothing, FileSize As Double = 0
    Try
    UploadFile = False
    If SourceLocation. ToString.Trim <> "" And
    DestinationLoca tion.ToString.T rim <> "" Then
    'To set Upload settings
    Dim UploadRequest As System.Net.Http WebRequest =
    CType(System.Ne t.WebRequest.Cr eate(New
    Uri(Destination Location.ToStri ng.Trim)), System.Net.Http WebRequest)
    UploadRequest.T imeout = 60000000
    UploadRequest.M ethod = "PUT"
    UploadRequest.C ontentLength = New
    System.IO.FileI nfo(SourceLocat ion.ToString.Tr im).Length
    FileSize = UploadRequest.C ontentLength.To String.Trim
    'To set Upload Stream settings
    Dim SourceStream As New
    System.IO.FileS tream(SourceLoc ation.ToString. Trim, System.IO.FileM ode.Open,
    System.IO.FileA ccess.Read, System.IO.FileS hare.ReadWrite)
    Dim RequestStream As System.IO.Strea m =
    UploadRequest.G etRequestStream ()
    Dim Buffer(4095) As Byte
    Dim Position As Integer = 0, ivlLoop As Integer = 0,
    CurLocation As Integer = 0
    Position = SourceStream.Re ad(Buffer, 0, Buffer.Length)
    ProgressBar.Vis ible = True
    ProgressBar.Val ue = 0
    ProgressBar.Max imum = 100
    While Position <> 0
    RequestStream.W rite(Buffer, 0, Position)
    Position = SourceStream.Re ad(Buffer, 0, Buffer.Length)
    CurLocation += Position
    ProgressBar.Val ue = CInt((CurLocati on / FileSize) * 100)
    ProgressBar.Ref resh()
    End While


    Dim WebResponse As System.Net.Http WebResponse =
    CType(UploadReq uest.GetRespons e(), System.Net.Http WebResponse)
    Dim ResponseReader As New
    System.IO.Strea mReader(WebResp onse.GetRespons eStream())
    Response = ResponseReader. ReadToEnd()
    UploadFile = True
    RequestStream.C lose()
    UploadRequest = Nothing
    SourceStream = Nothing
    RequestStream = Nothing
    WebResponse = Nothing
    ResponseReader = Nothing
    ElseIf SourceLocation. ToString.Trim = "" Then
    MsgBox("Source Location is missing", "UploadFile ")
    ElseIf DestinationLoca tion.ToString.T rim = "" Then
    MsgBox("Destina tion Location is missing", "UploadFile ")
    End If
    Catch ex As Exception
    MsgBox(ex.ToStr ing)
    Exit Function
    End Try
    'ProgressBar.Vi sible = False
    End Function

    --
    Get a powerful web, database, application, and email hosting with KJM
    Solutions




    "linn" <tanlh@ccn.com. sg> wrote in message
    news:1140516074 .162529.178140@ z14g2000cwz.goo glegroups.com.. .[color=blue]
    > The 'Address' parameter in the WebClient.Uploa dFile usually comes in
    > the form of ie. http://server/Upload_File.aspx
    >
    > Hence my question, what is exactly the content of this
    > Upload_File.asp x? Am i supposed to create this file with some specific
    > codes?
    >
    > Can't seems to get this method working for me in framework 2.0..
    >
    > Thanks for any help.
    >[/color]


    Comment

    • linn

      #3
      Re: Address parameter in WebClient.Uploa dFile?

      Thanks for your help.

      However, for the input parameter --> 'DestinationLoc ation' , I have
      supplied something like 'http://127.0.0.1/temp/' and I received a
      remote server returned an error: 405 Method not allowed.

      Is my DestinationLoca tion --> 'http://127.0.0.1/temp/' wrongly
      specified or could it be due to some other reason.

      Appreciate your advice.

      Thanks.

      Comment

      • vbnetdev

        #4
        Re: Address parameter in WebClient.Uploa dFile?

        Try using your actual IP address instead.

        Here are some steps to see if IIS is configured properly.

        Go to "Control Panel"-"Administra tive Tools"-"Internet Information
        Services".

        Expand the tree to "COMPUTERNA ME"-"Web Sites"-"Default Web Site".

        Right-click on "Default Web Site" and select "Properties ".

        Select the "Home Directory" tab.

        Click the "Configurat ion" button.

        From the "Mappings" tab, select the "Add" button.

        Click the "Browse..." button, choose "Dynamic Link Libraries *.dll" from the
        "Files of Type" dropdown, and select c:\WINDOWS\Syst em32\inetsrv\as p.dll.

        Type ".html" (without quotes) in the "Extension" box.

        Select the "Limit to:" radio button, and type in "GET, POST" (without
        quotes) in the box next to it.

        Click the "OK" button and close all the dialogs. (If the "OK" button is
        greyed out, then make sure all the entries are correct and try clicking in
        the file name box.)

        --
        Get a powerful web, database, application, and email hosting with KJM
        Solutions




        "linn" <tanlh@ccn.com. sg> wrote in message
        news:1140597631 .395449.292120@ g44g2000cwa.goo glegroups.com.. .[color=blue]
        > Thanks for your help.
        >
        > However, for the input parameter --> 'DestinationLoc ation' , I have
        > supplied something like 'http://127.0.0.1/temp/' and I received a
        > remote server returned an error: 405 Method not allowed.
        >
        > Is my DestinationLoca tion --> 'http://127.0.0.1/temp/' wrongly
        > specified or could it be due to some other reason.
        >
        > Appreciate your advice.
        >
        > Thanks.
        >[/color]


        Comment

        • linn

          #5
          Re: Address parameter in WebClient.Uploa dFile?

          Thanks.

          In fact, I have done all you have mentioned however it still fails. ;o(

          Comment

          • vbnetdev

            #6
            Re: Address parameter in WebClient.Uploa dFile?

            OK. Contact me on my site (my email link is there) and I will arrange a app
            sharing with you to see if we cna get to the bottom of this.

            --
            Get a powerful web, database, application, and email hosting with KJM
            Solutions




            "linn" <tanlh@ccn.com. sg> wrote in message
            news:1140661427 .977946.179550@ z14g2000cwz.goo glegroups.com.. .[color=blue]
            > Thanks.
            >
            > In fact, I have done all you have mentioned however it still fails. ;o(
            >[/color]


            Comment

            Working...