upload a pdf to SharePoint 2010 document collection site through VB Windows Form
I have a windows form in VB, and I am trying to accomplish the following:
1.) Convert a Crystal report to PDF and save it to a folder on local drive
2.) Upload the file to a known SharePoint Document Site collection through VB Code.
I have accomplished step 1, trying to complete step2.
Does anyone have code for uploading through VB a file to a SharePoint Document Site collection, or point me in the right path?
I take it that you just can't take sharepoint dll from the server, because SPS does not support remote calls unless the app resides on the SPS Server. I must use the web services.
OK - Got that, so how do I incorporate web services from SPS with Windows App?
BKennedy2008
ASKER
Do I use a an event reciever, and will I be able to call that remotely?
Thanks. I guess I do not want to use web services. I have a program already built in VB, and need to put an add on that will upload to SPS. I don't want to create a web app, but upload it directly from a windows form.
Sub UploadFileToSharePoint(ByVal UploadedFilePath As String, _
ByVal SharePointPath As String)
Dim response As WebResponse = Nothing
Try
' Create a PUT Web request to upload the file.
Dim request As WebRequest = _
WebRequest.Create(SharePointPath)
Dim networkCredential As New NetworkCredential("test", "test")
' Allocate a 1 KB buffer to transfer the file contents.
' You can adjust the buffer size as needed, depending on
' the number and size of files being uploaded.
Dim buffer() As Byte = New Byte(102300) {}
' Write the contents of the local file to the
' request stream.
Using stream As Stream = request.GetRequestStream()
Using fsWorkbook As FileStream = _
File.Open(UploadedFilePath, _
FileMode.Open, FileAccess.Read)
Dim i As Integer = fsWorkbook.Read(buffer, 0, _
buffer.Length)
Do While i > 0
stream.Write(buffer, 0, i)
i = fsWorkbook.Read(buffer, 0, buffer.Length)
Loop
End Using
End Using
' Make the PUT request.
response = request.GetResponse()
Catch ex As Exception
Throw ex
Finally
response.Close()
End Try
Now, if a user selects a file from the above code, How can I just pull the filename from the full path so I can make it a string the above "1.PDF" ?
Thanks
BKennedy2008
ASKER
Ok Success- create a function and add:
Dim sList() As String
Dim sAns As String
Dim iArrayLen As Integer
Dim fullpath As String = textbox1.Text
Dim namefromfullpath As String
If Len(fullpath) = 0 Then Exit Sub
sList = Split(fullpath, "\")
iArrayLen = UBound(sList)
sAns = IIf(iArrayLen = 0, "", sList(iArrayLen))
namefromfullpath = sAns
Thanks CodeCrusier for directing me in the right path....
http://www.r-tag.com/Pages/default.aspx
http://remicrystal.com/
http://www.jeff-net.com/jnrrb.htm
However, I don't think somebody will share code from a commercial tool.