Sharepoint File Upload via VB.NET

I recently had reason to upload a lot of files to Sharepoint 2010. Unfortunately the Upload item in the menu would only allow me to do this in batches of 100.  Fortunately however, you can do this from code.

    Public Function UploadToSharepoint(ByVal localFile As String, ByVal remoteFilename As String, spUrl As String, username As String, password As String, domain As String) As Byte()

        ' Ensure that we've got a valid URL.
        If Not spUrl.EndsWith("/") Then spUrl &= "/"

        ' Build the remote url, escape spaces and replace backslashes.
        Dim rfURL As String = String.Format("{0}{1}", spUrl, remoteFilename).Replace(" ", "%20").Replace("\", "/")

        ' Create a webclient.
        Dim wc As New WebClient
        wc.Credentials = New System.Net.NetworkCredential(username, password, domain)

        ' Attempt the upload.
        Try
            Using s As New System.IO.FileStream(localFile, IO.FileMode.Open, IO.FileAccess.Read)
                Using reader As New System.IO.BinaryReader(s)
                    UploadToSharepoint = wc.UploadData(rfURL, "PUT", reader.ReadBytes(CInt(s.Length)))
                End Using
            End Using

        Catch ex As Exception
            UploadToSharepoint = Nothing

        End Try

    End Function

Sunday Sickness

Years ago, before I became a responsible, upstanding member of the community, we always used to go out on Sunday night. From these Sunday night drinking sessions, a website was born. It existed only for a brief time, before apathy & lethargy laid it to waste. While we were out, various sketches were made on that day’s newspapers. I recently found these pictures during a laptop clean-out, and thought I’d post them here for posterity.

 

Mablefruitloop Online Handmade Loveliness!

Mablefruitloop Online Store

Please take 10 minutes out of your day to visit my better half’s online store. You can find it here:

http://mablefruitloop.co.uk/

While you’re here is would be fantastic if you could go and ‘Like’ the Facebook page too!:
Mable Fruitloop | Promote your Page too

Cheers!