My SharePoint Blog

Blogs On SharePoint Technologies


Search Site


My SharePoint Blog recommends any of the following books...


Recent comments

Tags

None

    Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    SharePoint Error PublicKeyToken=b77a5c561934e089 failed

    You'll get this error in your ASP.NET apps. Add the following your web.config for you non SharePoint web in your apps web.config file

     

    <system.web>
         <trust level="Full" originUrl="" />
    </system.web>

    Categories: SharePoint
    Posted by Kevin on Wednesday, April 18, 2007 1:04 PM
    Permalink | Comments (0) | Post RSSRSS comment feed

    WSS 3.0 API Notes

    The following misc code snippets are written in C# for the SharePoint API version 3.0. 

    using Microsoft.SharePoint;

    private function bool siteUsers()
    {
        SPSite siteCollection = new SPSite("http://localhost/");
        SPUserCollection SPUsers = siteCollection.AllWebs["/"].Users;  // root site

        foreach (SPUser SPUser in SPUsers)
        {
            Console.Write(SPUser.Name + "\r\n");
        }

        return true

    }

    private function doFoobar()

        Delete/Update SharePoint list items...

        SPSite siteCollection = new SPSite("http://localhost/");
        System.Net.NetworkCredential auth = new System.Net.NetworkCredential("userName", "password", "domain");
        siteCollection.credentials = auth;
        SPList list = siteCollection.AllWebs["sub_web_x"].Lists["List_Name"];
        /**********************************************
        Delete Existing SP list items
        **********************************************/
        SPQuery query = new SPQuery();
        query.Query = "";  // Send no conditions in query.  (btw, this is a CAML query type)
        SPListItemCollection listItems = list.GetItems(query);
        int listItemsCount = listItems.Count;

        for (int i = 0; i < listItemsCount; i++)
        {
            listItems.Delete(0);  // becuase the index slides as items are deleted, we simply delete the 0 index item repeatedly.
        }

        /**********************************************
        Load up records from a db table
        **********************************************/
        SqlConnection conn = new SqlConnection();
        SqlCommand cmd = new SqlCommand();
        conn.ConnectionString = "Data Source=db_Server;User ID=foo;Password=bar;Database=personel_db";
        conn.Open();
        cmd.Connection = conn;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "SELECT * FROM vContacts";
        SqlDataReader dataReader = cmd.ExecuteReader();
        // Load up records into SharePoint lists.
        int x = 0;

        while (dataReader.Read())
        {
            SPListItem newItem = listItems.Add();
            newItem["Last Name"] = dataReader["LastName"];
            newItem["First Name"] = dataReader["FirstName"];
            newItem["Middle Initial"] = dataReader["Minitial"];
            newItem["Nickname"] = dataReader["NickName"];
            newItem["Company"] = dataReader["Company"];
            newItem["Department"] = dataReader["Department"];
            newItem["Customer Phone"] = dataReader["CustomerPhone"];
            newItem["TEAS Office Phone"] = dataReader["TEASPhone"];
            newItem["E-mail Address"] = dataReader["EmpEmail"];
            newItem["Username"] = dataReader["UserName"];
            newItem.Update();
        }
        conn.Close();

        return true;
    }


    Categories: SharePoint
    Posted by Kevin on Tuesday, April 03, 2007 9:04 AM
    Permalink | Comments (0) | Post RSSRSS comment feed