Link to home
Start Free TrialLog in
Avatar of MikeXna
MikeXna

asked on

Creating a SharePoint List item and new directories on network share from Visual Basic 2010

Hello Experts,

I am working on a small windows form application using Visual Basic 2010.
I am looking to accomplish 2 things. (FYI - #1, I got - I need some help with #2)

1. Create a program/windows form (with the following fields: FirstName, LastName, CustomerNumber, and a button to click labeled "create folders") for my employees to fill out that will create several empty folders on a windows network share.

Example:
Z:\Customers
Z:\CustomerName12345
Z:\CustomerName12345\Purchases
Z:\CustomerName12345\Returns
The purpose for doing this is to create some commonality for how my employees manage their folders on my network share.  Note: I do not want users to save files to share point.

I have already achieved this quite easily using My.Computer.FileSystem.CreateDirectory _
("Z:\" & CustomerName & CustomerNumber) and so on for the subdirectories.

2. I created a SharePoint List called "Customers" With 3 fields (FirstName, LastName, and Folder). I want the "Folder" column to be formatted as a hyperlink that links to the appropriate folder (and opens a windows explorer window to that location) which was just created at the same time when my employees click the "create folders" button.

I am not a strong VB programmer and am seeking example code to "create a sharepoint list item" to accomplish this task.

Please let me know if you can help.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of colly92002
colly92002
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MikeXna
MikeXna

ASKER

Thanks.  This looks perfect.
Newbie Question: When I pasted the code into my project these first few lines have green underline:

Imports System
Imports Microsoft.SharePoint.Client
Imports SP = Microsoft.SharePoint.Client

When I mouse over them I get the following message:
"Namespace or type specified in the Imports Microsoft.SharePoint.Client doesn't contain any public Member or cannot be found. Make sure the namespace or type is defined and contains at least one public member"

I am sure i am missing something obvious. In visual basic, am I supposed to import any dlls into my solution explorer or something for the code to recognize?

Thanks
You are right you need to add the referenced .dlls to the project - if you started a new "Sharepoint" project in visual basic they will be there, but if not, just go to the  references box on the right hand side, right click add reference, and find the microsoft.Sharepoint.client.dll  (you might have to browse to the Sharepoint 14 hive to find it - if in doubt just google its path  because its in a standard directory).   As soon as you have added it it will work.
Avatar of MikeXna

ASKER

Got the dlls from MS download site after a google search.  The code now works,.
I was able to create a list item -- Thank You

2 Last questions.

1. Does the shareshpoint.client.dll need to be on every client/employee computer? When I build my project the exe in the debug folder works on my pc but not on a computer without the dlls.  Perhaps I am missing something obvious.  I never really published the project.

2. I was only able to create a list item but my text fields are not saving to sharepoint.  I am prompted with an error stating that the field on sharepoint does not exist.  I know it does... Perhaps It is a syntax thing in my code? Can strings be saved to sharepoint plain text fields?

Thanks again.
Yes you need the dll on each computer that this is going to run on - you can do this when you package up you project or you can just install the dll manually (I would learn how to build a deplyment package in visual studio personally - search for it in google there are lots of examples).

Sharepoint gives you horrendous error message - the "field does not exist" message just means that "something" is wrong.  It may be the syntax of the command or you maybe addressing your fields incorrectly.  Use the debugger to (put a breakpoint in the code and run the project) step through your code and see what line fails.  Always start by doing the simplest thing you can do and get that working, then build on it.  Sharepoint text fiedls will accept strings without complaint, just make sure there are no control characters in your string that might be confusing things, and that the size of your string is not bigger than your field definition.