XPathNavigator Root = MainDataSource.CreateNavigator();
XPathNavigator node = Root.SelectSingleNode(path, NamespaceManager);
if (node.MoveToAttribute("nil", System.Xml.Schema.XmlSchema.InstanceNamespace))
{
node.DeleteSelf();
}
node.SetValue(value);
if (string.IsNullOrEmpty(value)) //Empty date
{
string nil = node.GetAttribute("nil", System.Xml.Schema.XmlSchema.InstanceNamespace);
if (string.IsNullOrEmpty(nil))
{
try
{
node.MoveToFirstChild();
node.DeleteSelf();
node.CreateAttribute("xsi", "nil", System.Xml.Schema.XmlSchema.InstanceNamespace, "true");
}
catch (Exception ex)
{
}
}
}
Wednesday, September 12, 2012
Programmatically setting blank date value in InfoPath form Date Picker.
Thursday, August 27, 2009
Adding Files into a SharePoint document library from Buffer
SPWeb Site = new SPSite( "http://server/sites/test%22).OpenWeb() );
Site.AllowUnsafeUpdates = true;
string FileContent = "File Data";
byte[] Contents = Encoding.UTF8.GetBytes(FileContent);
Site.Files.Add(NewFilePath, Contents);
Tuesday, July 7, 2009
Using Data Connection Library with InfoPath
Moving InfoPath Data Connections into Data Connection Library:
1. Create a Data connection library( Site Actions -> Create -> Select “Data Connection Library” )
2. Give name and copy newly created “Data Connection Library” URL, e.g.: http://idc-lt-i00142/sites/test/DataConnections
3. Open InfoPath from in design mode open data connections( Tools => Data Connections)
4. Select Data connection which needs to move to the “Data Connection Library” and click “Convert” button.
5. Give previously created “Data Connection Library” name append with name of the data connection(Any name). e.g. http://idc-lt-i00142/sites/test/DataConnections/MainSubmit
6. Select “Relative to Site Collection” radio button and click OK.
7. This will create an entry in previously created “Data Connection Library” and the InfoPath form always check the data source path from “Data Connection Library” with same name in the same site level.
Deploying Data Connections from one site to another site ( say development to production).
These steps to be done when a site is moving from one place to another. These is one time process, no need to repeat this on each publish of the form. Form always reads Data Source path from corresponding “Data Connection Library”.
1. Move data connection library into the destination site collection into the same level. This can be done either by restoring site backup or by creating List Template of with data and create new data connection library in the destination site at same level.
2. Open each item( .udcx files) in the destination “Data Connection Library” in any xml editor( notepad or Visual Studio etc) ( Action -> Open in windows explore -> copy to local drive -> open.)
3. Change the data connection URLS in the .udcx files save and upload again.
e.g.
Update ” http://SourceServer/sites/site/FromLibrary” in “
Repeat this for all data connection library.
4. So in the new site InfoPath always refer new Data Connection library in the newly added site.
Wednesday, August 20, 2008
Error occurring while restoring backup is from a different version of Windows SharePoint Services
"Your backup is from a different version of Windows SharePoint Services and cannot be restored to a server running the current version. The backup file should be restored to a server with version '12.0.0.6300' or later"
Resolution:
Upgrade Windows SharePoint Services using KB article: KB941422 [ http://www.microsoft.com/downloads/details.aspx?familyid=78549F3C-3CD2-445E-9DC0-417CA5A4A079&displaylang=en ]
Run SharePoint configuration wizard after installing this hot fix.
Sunday, April 27, 2008
Get SPUser's for a SPRole in a Sharepoint Site
Site Settings > Advanced permissions > Settings > Permission Levels > Add a Permission Level
To access all users having a particular Permission Level.
public string GetEmailForRole(string RoleName)
{
const string NDA_SITENAME = http://Server:801/sites/SiteName;
StringBuilder EmailList = new StringBuilder();
SPSite NDASite = new SPSite(NDA_SITENAME);
SPWeb NDAWeb = NDASite.OpenWeb();
foreach (SPRole role in NDAWeb.Roles)
{
if (role.Name == RoleName )
{
SPUserCollection spusers = role.Users;
foreach (SPUser user in spusers)
{
if( user.Email != "")
{
EmailList.Append(user.Email);
EmailList.Append(";");
}
}
}
}
return EmailList.ToString();
}
Monday, February 18, 2008
Setting item level security in SharePoint List
SPWeb NDAWeb = NDASite.OpenWeb();
SPList COIList = NDAWeb.Lists[LIST_NAME];
SPListItemCollection listItems = COIList.Items;
SPGroup Group = NDAWeb.SiteGroups["test"];
SPRoleAssignment gr = new SPRoleAssignment(Group);
SPRoleDefinition role = NDAWeb.RoleDefinitions["Contribute"];
gr.RoleDefinitionBindings.Add(role);
//For each item in the list
foreach (SPListItem item in listItems)
{
//Break inheritance
item.BreakRoleInheritance(true);
//Get SPRoleAssignmentCollection
SPRoleAssignmentCollection sr = item.RoleAssignments;
//Removeing all current permissions if needs..
for (int i = 0; i < sr.Count; i++)
{
sr.Remove(i);
}
//Add group to SPRoleAssignmentCollection
sr.Add(gr);
//gr.Update(); - no need to update
}
Thursday, February 14, 2008
Get Internal Name of list Item:
Get Internal Name of list Item:
SPSite Site = new SPSite("SiteURI");
SPWeb Web = Site.OpenWeb();
SPList List = Web.Lists["List Name"];
string ColumnName = "My Field Name"; //Name of the field as in list settings
//Update field name with internal name of the column
for (int fc = 0; fc < List.Fields.Count; fc++)
{
if (List.Fields[fc].Title == ColumnName )
{
ColumnName = List.Fields[fc].InternalName;
}
}
string query = "<Query>";
query += " <Where>";
query += " <Eq>";
query += " <FieldRef Name="Author" />";
query += " <Value Type="User">shaiju</Value>";
query += " </Eq>";
query += " </Where>";
query += "</Query>";
SPQuery Query = new SPQuery();
Query.Query = query;
SPListItemCollection listItems = COIList.GetItems(Query);
foreach (SPListItem item in listItems)
{
temp = string.Empty;
try
{
temp = item[ColumnName].ToString();
}
catch (NullReferenceException) { }
if (temp == "E1457")
{
MessageBox.Show(item[ColumnName].ToString());
}
}