Tuesday, December 1, 2009

View based on current user in sharepoint groups

But I think it is missing a view in which someone can filter what tasks are either directly assigned him or any of the Active Directory Group/SharePoint Group he belongs to




<Query><Where><Or><Membership Type="CurrentUserGroups"><FieldRef Name="Branch"/></Membership><Membership Type="CurrentUserGroups"><FieldRef Name="ATH"/></Membership></Or></Where></Query>


Replace
"<" with <
">" with >
" " " with "

Saturday, November 28, 2009

Custom Action in Sharepoint Designer Workflow

Very useful link proud to share

http://sarangasl.blogspot.com/2009/11/sharepoint-workflow-actions-for.html
http://blogit.create.pt/blogs/ricardocosta/archive/2007/11/02/Custom-Action-for-Sharepoint-Designer.aspx

Thursday, March 5, 2009

Add user in SP site Programatically

SPSite thisSite1 = SPControl.GetContextSite(HttpContext.Current);
SPWeb web = thisSite1.OpenWeb();
web.AllowUnsafeUpdates = true;
web.SiteUsers.Add("bomcordom:" + _userid, "", _userid, "");
web.Groups[].AddUser("bomcordom:" + _userid, "", _userid, "");

Friday, February 13, 2009

Programmatically add users to Active Drirectory

string strUserID = "user123";
string Fullname = "User1";
string password = "pass";
string office = "B" + strUserID;

try
{
DirectoryEntry objEntry = new DirectoryEntry();
objEntry.Path = "LDAP://AAA.com/DC=AAA,DC=com";
objEntry.Username = "AAA\\misadmin";
objEntry.Password = "mis";


DirectorySearcher userSearch = new DirectorySearcher();
userSearch.SearchRoot = objEntry;
userSearch.Filter = "(&(objectClass=user)(CN=" + strUserID + "))";
SearchResultCollection uColl = userSearch.FindAll();
if (uColl.Count == 0)
{
objEntry.Path = "LDAP://AAA.com/OU=MUsers,DC=AAA,DC=com";

//Add new user Account
DirectoryEntries users = objEntry.Children;
DirectoryEntry user = users.Add("CN=" + strUserID, "User");

//Set user properties

user.Properties["sAMAccountName"].Add(strUserID);
//Logon Name
user.Properties["userPrincipalName"].Add(strUserID + "@AAA.com");
//First Name
user.Properties["givenName"].Add(Fullname);
//Display Name
user.Properties["displayName"].Add(Fullname);
//Office
user.Properties["physicalDeliveryOfficeName"].Add(office);
user.CommitChanges();

//Set Password
object objRet = user.Invoke("SetPassword", password);
user.CommitChanges();

//Password never expires
int exp = (int)user.Properties["userAccountControl"].Value;
user.Properties["userAccountControl"].Value = exp | 0x1;
user.CommitChanges();

//Enable user account
int val = (int)user.Properties["userAccountControl"].Value;
user.Properties["userAccountControl"].Value = val & ~0x2;
user.CommitChanges();

user.Close();
objEntry.Close();

Response.Write(strUserID +" ----- User successfully added to domain");
}
else
{
Response.Write("User already exists");
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}

Tuesday, October 7, 2008

"File not found error..." whenu click on Layouts folder files..

ASP.Net Config Tool and MOSS 2007



Today our SharePoint server raised a nice exception: ‘File not Found’ when you tried to log on. Off course we were already familiar with the sound exceptions SharePoint raises so we inspected the event log.
Error: Failure in loading assembly: Microsoft.SharePoint.Portal, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c
Error: Failure in loading assembly: Microsoft.SharePoint, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c

The solution was pretty forward, but raises the question how compatible is Microsoft with Microsoft…..

It seems that when you modify the web.config with the ASP.Net Configuration Tool, it adds an attribute (xmlns) to the <configuration> tag like so: <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
so remove the attribute (xmlns) now thwe site would work.

Programatticaly Upload a document to Sharepoint List

Content of Design File:









Content Of Code File:


protected void Button1_Click(object sender, EventArgs e)
{
byte[] contents;
SPSite sp = new SPSite("");
SPWeb site = sp.OpenWeb();
site.AllowUnsafeUpdates = true;
SPList list = site.Lists["Test"];
SPListItem myNewItem;

string strDate = System.DateTime.Now.Date.TimeOfDay.ToString();
myNewItem = list.Items.Add();
string fileName = File1.Value.Substring(File1.Value.LastIndexOf("\\") + 1);

string strFilepath = File1.Value.ToString();
StreamReader sr = new StreamReader(strFilepath);
Stream fStream = sr.BaseStream;
contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
myNewItem["Title"] = "Sendil";


myNewItem.Attachments.Add(fileName, contents);
myNewItem.Update();
// System.IO.File.Delete(strFilepath);---> Deleting a source file.......
}