Microsoft Word - Word VBA 2007: Need help getting started programming with SharePoint

Asked By Avi Makeler on 14-Aug-11 02:58 PM

Word VBA 2007: Need help getting started programming with SharePoint

Hi all,

I have had quite a lot of experience in programming in VBA, especially for Word - but so far no Sharepoint.

So now all of a sudden as part of a template design project with some VBA support programming, I may be required to write some code to save or update documents in SharePoint and also update their version numbers.

So I need some pointers to help me get started programming with SharePoint

Does Word VBA support SharePoint?

What are the new objects? What methods perform the save and update? Do you need to supply an HTTP address for the SharePoint area? Or is it implicit? How do you open and save? Check in and check out? How do you get and set the version number?

Great thanks in advance.

-avraham

Ravi S replied to Avi Makeler on 14-Aug-11 03:09 PM
hi

SharePoint 2010 Development Platform provides

1. Value added functionality such as Lists, document Libraries, Announcements, Tasks, together with the ability to access other data, including data stored in relational databases.

2. SharePoint–specific project templates to Visual Studio to create and maintain applications for the SharePoint Environment.

3. Business logic support using ASP.NET pages, Workflows based on Windows Workflow Foundation (WF).

To build ASP.NET application from scratch, we need to design user interface, perform database design and host and configure application on web server. Most of organization created their own framework on the top of ASP.NET. Using SharePoint platform is a good idea. With the help of Template Based Solutions in SharePoint Foundation 2010, web application creation and customization become simple.

REFER

http://www.learningtree.com/courses/2615.htm

http://learndotnetprogramming.com/quick-learn-dot-net-programming/quick-sharepoint-2010/

Ravi S replied to Avi Makeler on 14-Aug-11 03:15 PM
Hi
 
I will start with creating a new console application (make sure you are working on your server) with Visual Studio 2010.

Add references for the following assemblies:

Microsoft.Office.Server.dll
Microsoft.SharePoint.dll

Both of them can be found inside the 14\ISAPI folder of your server.
Also add reference for:

System.Web

Make sure to also add the necessary using statements.
When all of this is sorted we can start coding!
First of all we need connection with the SharePoint Server.

using (SPSite site = new SPSite("http://yourServer"))
{
     SPWeb web = site.OpenWeb();
     site.AllowUnsafeUpdates = true;
     web.AllowUnsafeUpdates = true;
     SPListCollection coll = web.Lists;
 }
We use SPSite to connect to our SharePoint Site, to access the Lists we also need a SPWeb object.
So we can get all the available lists using the SPWeb.Lists command.

Before I continue with any code, I would like to mention that to add a new List we need:
SPWeb object
A Title
A Description
A SPListTemplateType object

The necessary SPFields, which are the “columns”
I will continue pasting the previous code and adding the new code.

using (SPSite site = new SPSite("http://yourServer"))
{
     SPWeb web = site.OpenWeb();
     site.AllowUnsafeUpdates = true;
     web.AllowUnsafeUpdates = true;
     SPListCollection coll = web.Lists;
  
     Guid gd = coll.Add("ListTitle", "ListDescription", SPListTemplateType.CustomGrid);
 }

With the new line of code i have added we are adding a new List with the specified title, description and ListTemplateType.
After adding the List this function will return the Guid of the new List. This Guid we need to add the “columns” called SPFields.
To add a column to the new list we use the following command

coll[Guid].Fields.Add("ColumnTitle", SPFieldType.Text, true);

This function expects 3 parameters: a title for the column, the type for the column (text, boolean, ..), and a boolean whether it is required or not to enter content in this Field.
So we can use this to add some columns to our new list

using (SPSite site = new SPSite("http://yourServer"))
{
     SPWeb web = site.OpenWeb();
     site.AllowUnsafeUpdates = true;
     web.AllowUnsafeUpdates = true;
     SPListCollection coll = web.Lists;
  
     Guid gd = coll.Add("ListTitle", "ListDescription", SPListTemplateType.CustomGrid);
     coll[gd].Fields.Add("FirstName", SPFieldType.Text, true);
     coll[gd].Fields.Add("LastName", SPFieldType.Text, true);
     coll[gd].Fields.Add("Married", SPFieldType.Boolean, true);
     coll[gd].Update();
 }

By using the Update method we execute the changes.
The next stap is adding a custom View, before we do this we delete the existing View.

using (SPSite site = new SPSite("http://yourServer"))
{
     SPWeb web = site.OpenWeb();
     site.AllowUnsafeUpdates = true;
     web.AllowUnsafeUpdates = true;
     SPListCollection coll = web.Lists;
  
     Guid gd = coll.Add("ListTitle", "ListDescription", SPListTemplateType.CustomGrid);
     coll[gd].Fields.Add("FirstName", SPFieldType.Text, true);
     coll[gd].Fields.Add("LastName", SPFieldType.Text, true);
     coll[gd].Fields.Add("Married", SPFieldType.Boolean, true);
     coll[gd].Update();
  
     string defaultquery = coll[gd].Views[0].Query;
     SPViewCollection viewcoll = coll[gd].Views;
     Guid anothergd = coll[gd].Views[0].ID;
     viewcoll.Delete(anothergd);
 }

Before we delete the existing view we wanna keep the Query, to use it in our new View.
After this View is deleted we can add our custom View.
To add a View we need “ViewFields” which refer to the ListFields.

using (SPSite site = new SPSite("http://yourServer"))
{
     SPWeb web = site.OpenWeb();
     site.AllowUnsafeUpdates = true;
     web.AllowUnsafeUpdates = true;
     SPListCollection coll = web.Lists;
  
     Guid gd = coll.Add("ListTitle", "ListDescription", SPListTemplateType.CustomGrid);
     coll[gd].Fields.Add("FirstName", SPFieldType.Text, true);
     coll[gd].Fields.Add("LastName", SPFieldType.Text, true);
     coll[gd].Fields.Add("Married", SPFieldType.Boolean, true);
     coll[gd].Update();
  
     string defaultquery = coll[gd].Views[0].Query;
     SPViewCollection viewcoll = coll[gd].Views;
     Guid anothergd = coll[gd].Views[0].ID;
     viewcoll.Delete(anothergd);
  
     System.Collections.Specialized.StringCollection viewfields = new System.Collections.Specialized.StringCollection();
     viewfields.Add("Title");
     viewfields.Add("FirstName");
     viewfields.Add("LastName");
     viewfields.Add("Married");
  
    coll[gd].Views.Add("View name", viewfields, defaultquery, 100, true, true);
    coll[gd].Update();
 }

refer
Avi Makeler replied to Ravi S on 14-Aug-11 04:03 PM
Ummm ... no VBA ...?

-avraham