views:

123

answers:

0

Hello Experts, I am trying to upload some files from local machine to Sharepoint document library.

The file I am trying to upload is c:/uploads/route.pdf

My sharepoint site URL is http://companyportal:9191/Sites/Travel

I have a document library called Travel docs under Shared Documents. The actual URL for the document library is http://companyportal:9191/Sites/Travel/Shared Documents/Travel docs/Forms/Allitems.aspx

I need your help in finding what should be the values for sSPURL, sDocLib,

Public Function UploadDocument(ByVal localFile As String, ByVal remoteFile As String) As String
        '// Read in the local file
        On Error GoTo handler
        Dim r As Byte()
        Dim Strm As System.IO.FileStream = New System.IO.FileStream(localFile, System.IO.FileMode.Open, System.IO.FileAccess.Read)
        Dim reader As System.IO.BinaryReader = New System.IO.BinaryReader(Strm)
        Dim filecontents As Byte() = reader.ReadBytes(CInt(Strm.Length))
        reader.Close()
        Strm.Close()
        Dim sSPURL As String = ConfigurationManager.AppSettings("SharePointServer")
        Dim sDocLib As String = ConfigurationManager.AppSettings("DocLibrary")
        Dim sUser As String = ConfigurationManager.AppSettings("User")
        Dim sPwd As String = ConfigurationManager.AppSettings("Pwd")
        Dim sDomain As String = ConfigurationManager.AppSettings("Domain")
        Dim sRemoteFileURL As String
        Dim NC As System.Net.NetworkCredential = New System.Net.NetworkCredential(sUser, sPwd, sDomain)
        sRemoteFileURL = sSPURL & "/" & sDocLib & "/" & Trim(LTrim(RTrim(remoteFile)))

        sRemoteFileURL = Replace(sRemoteFileURL, " ", "%20")
        sRemoteFileURL = Replace(sRemoteFileURL, "\", "/")
        Dim m_WC As WebClient = New WebClient
        m_WC.Credentials = NC
        r = m_WC.UploadData(sRemoteFileURL, "PUT", filecontents)
        Return "TRUE"
        Exit Function
handler:
        Return Err.Description
    End Function