Results 1 to 3 of 3

Thread: upload excel file

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Location
    Philippines
    Posts
    2

    Post upload excel file

    i tried to upload an excel file using the following code:

    myWebClient.UploadFile("\\146.51.237.157 test\FromArray.xls", "POST", "C:\FromArray.xls")

    The upload was successful but the content was changed into ASCII characters.

    Please give me some advise. Thanks.

  2. #2
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    Re: upload excel file

    I use this:
    VB Code:
    1. Imports System.Data
    2. . . .
    3.  Dim cnnString As String = _
    4.            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\Excel\test.xls;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"""
    5.         Dim cnn As New OleDb.OleDbConnection
    6.         Dim cmd As New OleDb.OleDbCommand
    7.         Dim da As New OleDb.OleDbDataAdapter
    8.         Dim ds As New DataSet
    9.         Try
    10.             cnn.ConnectionString = cnnString
    11.             cnn.Open()
    12.             cmd = cnn.CreateCommand
    13.             cmd.CommandText = "SELECT * FROM [Sheet1$]"
    14.             da.SelectCommand = cmd
    15.             da.Fill(ds, "ExcelSheet")
    16.  
    17.             DataGrid1.DataSource = ds.Tables("ExcelSheet")
    18.  
    19.         Catch oEx As Exception
    20.             Console.WriteLine(oEx.ToString)
    21.         Finally
    22.             cnn.Close()
    23.         End Try

  3. #3

    Thread Starter
    New Member
    Join Date
    Jun 2005
    Location
    Philippines
    Posts
    2

    Re: upload excel file

    Thank you for your quick response.
    We are using the WebClient class. Do you know how to upload using this class? The upload is actually successfull. The only problem is that the contents is changing during the process. This is my code:

    Dim myWebClient As New WebClient

    Dim strLocalFile As String = txtUploadFile.Text
    Dim strServerPath As String = "\\146.51.237.157\test\"
    Dim strFilename As String = fnGetFileName(strLocalFile)

    Dim strServerLocation As Byte() = myWebClient.UploadFile(strServerPath + strFilename, "POST", strLocalFile)

    Thank you very much for your help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width