October 12, 2009

Sharepoint: XML File Upload, File Level,Folder Level, Group Creation etc

---XML Doc---
<?xml version="1.0" encoding="utf-8" ?>
Products>
<Product Name="Product1">
<File>
<Title>1.txt</Title>
<Groups>One,Two,Three</Groups>
</File>
<File>
<Title>2.txt</Title>
<Title>3.txt</Title>
<Groups>Two</Groups>
</File>
<File>
<Title>4.txt</Title>
<Title>5.txt</Title>
<Groups>Three</Groups>
</File>
</Product>
<Product Name="Product2">
<File>
<Title>6.txt</Title>
<Title>7.txt</Title>
<Groups>Four,Six</Groups>
</File>
</Product>
<Product Name="Product3">
<File>
<Title>8.txt</Title>
<Title>9.txt</Title>
<Groups>Five</Groups>
</File>
</Product>
<Product Name="Product4">
<File>
<Title>10.txt</Title>
<Title>11.txt</Title>
<Groups>Five,Six</Groups>
</File>
</Product>
</Products>
---Button Click---
DirectoryInfo Dir = new DirectoryInfo(@"FolderURL");
FileInfo[] CxiFiles = Dir.GetFiles();
foreach (FileInfo fi in CxiFiles)
{
XmlTextReader Reader = new XmlTextReader(Dir.ToString() + fi.ToString());
Reader.WhitespaceHandling = WhitespaceHandling.None;
XmlDocument XmlDoc = new XmlDocument();
XmlDoc.Load(Reader);
Reader.Close();
XmlNode RootNode = XmlDoc.DocumentElement;
Children(RootNode, 1);
lines = lines.Replace("|", "\r\n");
}

------Main Logic---
private void Children(XmlNode xnod, Int32 intLevel)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
XmlNode xnodWorking;
XmlNode node1;
string ListName = "Docs";
SPSite siteCollection = new SPSite(@"URL");
SPWeb siteWeb = siteCollection.RootWeb;
SPListCollection spList = siteWeb.Lists;
SPFolder spFolder = null;
if (xnod.Name.Substring(0, 4) == "Prod")
{
if (siteWeb.GetFolder(ListName + "/" + xnod.Attributes[0].Value).Exists == true)
{
spFolder = siteWeb.Folders[ListName].SubFolders[xnod.Attributes[0].Value];
SPListItem item = spFolder.Item;
item["DocType"] = "Folder";
item["Product Name"] = spFolder.Name;
item.Update();
}
else
{
spFolder = siteWeb.Folders[ListName].SubFolders.Add(xnod.Attributes[0].Value);
SPListItem item = spFolder.Item;
item["DocType"] = "Folder";
item["Product Name"] = spFolder.Name;
item.Update();
}
}
if (xnod.Name.Substring(0, 4) == "File")
{
node1 = xnod.FirstChild;
while (node1 != null)
{
spFolder = siteWeb.Folders[ListName].SubFolders[xnod.ParentNode.Attributes[0].Value];
spFolder.Item.BreakRoleInheritance(false);
siteWeb.AllowUnsafeUpdates = true;
if (node1.Name.Substring(0, 1) == "T")
{
string FilePath = @"C:\Source Folder\" + node1.InnerText;
string FileName = System.IO.Path.GetFileName(FilePath);
string DocType = node1.Attributes["DocType"].Value;
System.IO.FileStream Strm = new System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
System.IO.BinaryReader reader = new System.IO.BinaryReader(Strm);
Byte[] filecontents = reader.ReadBytes(Convert.ToInt32(Strm.Length));
reader.Close();
Strm.Close();
spFolder.Files.Add(System.IO.Path.GetFileName(FilePath), filecontents, true);
SPListItem item = file.Item;
item["DocType"] = DocType;
item["Product Name"] = spFolder.Name;
item.Update();
node1 = node1.NextSibling;
}
else
if (node1.Name.Substring(0, 1) == "G")
{
//string Grps = xnod.FirstChild.NextSibling.InnerText;
string Grps = node1.InnerText;
string[] grps = Grps.Split(',');
foreach (string g in grps)
{
try
{
if (siteWeb.SiteGroups[g] != null)
{
SPGroup group2 = siteWeb.SiteGroups[g];
SPRoleDefinition RoleDefinition = siteWeb.RoleDefinitions["Read"];
SPRoleAssignment RoleAssignment = new SPRoleAssignment((SPPrincipal)siteWeb.SiteGroups[g]);
RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);
siteWeb.RoleAssignments.Add(RoleAssignment);
spFolder.Item.RoleAssignments.Add(RoleAssignment);
SPList lst = siteWeb.Lists[ListName];
SPListItemCollection items = lst.Items;
foreach (SPListItem item in items)
{
foreach (XmlNode x in node1.ParentNode.ChildNodes)
{
if (item.Name == x.InnerText)
{
item.BreakRoleInheritance(false);
item.RoleAssignments.Add(RoleAssignment);
item.Update();
}
}
}
}
}
catch (SPException ex)
{
SPMember member = siteWeb.SiteUsers["admembershipprovider:krish.banerjee"];
SPUser usr = siteWeb.SiteUsers["admembershipprovider:krish.banerjee"];
siteWeb.SiteGroups.Add(g, member, usr, g);
AddToValidDomains(g);
SPGroup group2 = siteWeb.SiteGroups[g];
SPRoleDefinition RoleDefinition = siteWeb.RoleDefinitions["Read"];
SPRoleAssignment RoleAssignment = new SPRoleAssignment((SPPrincipal)siteWeb.SiteGroups[g]);
RoleAssignment.RoleDefinitionBindings.Add(RoleDefinition);
siteWeb.RoleAssignments.Add(RoleAssignment);
spFolder.Item.RoleAssignments.Add(RoleAssignment);
SPList lst = siteWeb.Lists[ListName];
SPListItemCollection items = lst.Items;
foreach (SPListItem item in items)
{
if (item.Name == node1.PreviousSibling.InnerText)
{
item.BreakRoleInheritance(false);
item.RoleAssignments.Add(RoleAssignment);
item.Update();
}
}
}
}
spFolder.Update();
node1 = node1.NextSibling;
}
}
}
if (xnod.NodeType == XmlNodeType.Element)
{
if (xnod.HasChildNodes)
{
xnodWorking = xnod.FirstChild;
while (xnodWorking != null)
{
Children(xnodWorking, intLevel + 1);
xnodWorking = xnodWorking.NextSibling;
}
}
}
lblError.Text = "Success";
});
}

Feedback Workflow Attributes: Sharepoint

Just a quick handy for creating a Sharepoint workFlow sending an email.

1. Actions for Post WorkFlow
1. Subject: CurrentItem:Title
2. Posted By: CurrentItem:PostedBy
3. EncodedAbsoluteUrl/../Post.aspx?ID=CurrentItem:ID
4. span...p..b..body...b..p..span
5. Thanks
2. Actions for Comments WorkFlow
1. Subject: CurrentItem:PostTitle
2. Posted By: Feedbacks..PostedBy..Feedbacks:CreatedBy...Comments:CreatedBy
3. Url: Feedbacks...EncodedUrl...Feedbacks:ID...Comments:PostID
4. Ur;/../Post.aspx?ID=
5. ID: Feedbacks...ID...Feedbacks:ID...Comments:ID
6. Thanks

October 07, 2009

Scopes---Sharepoint

Step 1: Go to "Site Actions", "Site Settings" and under "Site Collection Administration" click on "Search Scopes".

Step 2: Click on "New Scope" and give it a title. Usually the document library you wish to search. Click "OK"

Step 3: Now we need to add a rule. Go to the document library you wish to search and grab the URL. Then repeat Step 1 to get back to the search scope settings page. Click on the search scope you created in Step 2. Under the "Rules" section click on "New Rule". Select "Web Address" and enter the URL of your document library. Click "OK".

Step 4: Click on "New Display Group" and give it a title and a description. In the "Scopes" section select the scope you created in Step 2. The "Default Section" should automatically become the scope you selected.

Step 5: Wait for the server to recognize the new scope and display group.

Step 6: Go back to the page you wish to add a search box. Go to "Site Actions", "Edit Page", click on "Add a Web Part". Select the "Search Box" web part and click "Add".

Step 7: The page should be in "Edit Mode". In the "Search Box" web part click on the "edit" button and go to "Modified Shared Web Part".

Step 8: Expand the "Miscellaneous" section. Uncheck "Use site level defaults". In the "Scope Display Group" sub-section the default display group scope will be "Search Dropdown" change this to the display group you created in Step 4. You cannot browse through the display groups so you will have to type your display group in exactly. Click on "OK".

Step 9: Exit out of "Edit Mode". Your search box should now have the new search scope you created in Step 2 as the default choice.

October 06, 2009

Open A Document in new Window..Sharepoint

Hi All,

Let's take one scenario where your client does not have office installed and you also want to deal with document library.

Now we know that there is a settings in document library settings that if client do not have office installed at machine, then MOSS will automatically open document in the browser window. it automatically check for the availability of office at client side and if not found then opens it in same browser.

The settings for this is as follows :

(1) Go to your document library.
(2) Click on Settings-> document library settings
(3) Click on advanced settings
(4) Check for "Browser-enabled Documents" section and select Display as a Web page.
(5) Press OK.

Now you have set this option and if your client does not have office installed then MOSS will automatically open document in browser.

but but but.....notice that it opens in same browser...So if you want that document opens in new windows, not in the same browser then.....???

so Here is a trick to go for it :

But remember that this change will apply to all document libraries of all web applications. Because we are going to change the Global onet.xml. So be aware..

Here we go..
(1) Open C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\GLOBAL\XML
(2)Open ONET.XML
(3)Search for this line onfocus="OnLink(this)" HREF="
(4)Change it to OnLink(this)" target="_new" HREF="
(5)Rest the IIS and just check.....
now all documents will open in new window..
Source: http://www.sharepointkings.com/2008/07/open-documents-in-new-window.html#

Sharepoint Errors and Solutions

1. Constraint violation Occured:
Solution: delete from AD and create again.
2. Invalid Padding Cryptographic Exception
Solution: In web.config of site, Add this under system.web
<machinekey validationKey="6DFDCDE9B71CA61A8DB213CA721B94E4636322D8B675CCD7"
decryptionKey="D0AA80E9A03C73823C7108E11046986717152C97EAEA7C02" validation="SHA1" />
3. Contsratint Violation from Directory Services
Solution: Attribute Editor in AD, attributeMapFailed.....
4. Service Unavailabe when accesing Sites
Solution: Application Pool may be disabled.
1. Configurable in Application Pool Properties ...the password might be changed.
5. net accounts [For Setting Password Policy in AD]
net accounts /minpwage:7
net accounts /minpwlen:7
net accounts /uniquepw:5
6. If role provider doesn't work..see the trust level = "Full" or not.
7. For Account Password Lockout Policy
.....Local Policy settings[Default Grayed Out]
.....From command Line
.....First Set net accounts /lockoutthreshold:30
...............net accounts /lockoutduration:30
...............net accounts /lockoutwindow:30
.....Now you can play aorund from UI itslef
8. You do not have nbecessar permisions...while deploying workflows using sharepoint designer.
Solution:
Click Start, point to All Programs, point to Microsoft Office Server, and then click SharePoint 3.0 Central Administration.
Click the Operations tab.
Under Security Configuration, click Service Accounts.
Click Web application pool, and then click Windows SharePoint Services Web Application in the Web service box.
In the Application pool box, click the application pool that you want to change.
Under Select an account for this component, click Configurable, and then type the user name
and the password for the different user account.
9. Encoded Absolute URl in Custom Workflow email..getting the last part as number.
Solution: [EncodedAbsoulteURL]/../Post.aspx?ID=[ID]
For Comments: Same as above with Lookup to parent one with ID's....I mean relate with PostId
10. How-To Delete SharePoint Shared Services Provider (SSP)
Dont Delete the databases before making sure in website they are deleted, otherwise ssp cannot be deleted.
stsadm -o deletessp -title YourSSPTitleHere -force
11. To Run stsadm commands from anywher
....Start---Control Panel---System---Advanced---Environmental variables---Path---Edit.
At the end of line add ;C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\BIN
12. Windows SharePoint Services Web Application [Never Ever Restart This Service]
When you stop the Web Application service,
it actually undeploys all the vdirs from IIS
and deletes the IIS web sites. Starting it deploys these again.
13. Crawling can be done only against Windows Authentication Websites.
If we have any forms based authentication then extend the website and give that url in the content sources crawling.
14. Internet Not Working in Server.
Server-->Set up DNs Correctly in TCP-IP Properties with Corect Primary IP.
15. Error:
One or more field types are not installed properly. Go to the list settings page to delete these fields.
Solution: Reset IIS first. if still prevails..it's problem with definitions change for the columns and column removals. Dont remove any column and it will work.
16. Restricting Access to tabs in Menu
Solution: Give Relative URL Like /sites/.... instead of absulute URL.
17. IP Address not resolving.
Solution: Central Admin..Operations...Alternative Access mapping..Give The Ip address in the Internet section
18. In the GetItems(SPQuery)..the SPQUERY should not have the query tag, otherwise it will bring all the items.

October 01, 2009

Create a New SharePoint Permission Level and Bind it to an Existing SharePoint Group

This example will create a new permission level, called Example_xxxxxxxxxxx. After creation, it binds the permission level to an existing SharePoint Group called Foo.

using (SPSite site = new SPSite( "http://moss/sites/PermExample" ))
{
using (SPWeb rootWeb = site.RootWeb)
{
string permissionLevelName = "Example_"+System.DateTime.Now.Ticks.ToString();

// Create a new Permission Level
SPRoleDefinition newPermissionLevel = new SPRoleDefinition();
newPermissionLevel.Name = permissionLevelName;
newPermissionLevel.Description = "Example Permission Level";
newPermissionLevel.BasePermissions =
SPBasePermissions.AddListItems |
SPBasePermissions.BrowseDirectories |
SPBasePermissions.EditListItems |
SPBasePermissions.DeleteListItems |
SPBasePermissions.AddDelPrivateWebParts;

// Add the permission level to web
rootWeb.RoleDefinitions.Add(newPermissionLevel);

// Bind to the permission level we just added
newPermissionLevel = rootWeb.RoleDefinitions[permissionLevelName];

// Create a new role Assignment using the SharePoint Group "Foo"
SPRoleAssignment roleAssignment = new SPRoleAssignment( (SPPrincipal)rootWeb.SiteGroups[ "Foo" ] );

// Add the Permission Level to the Foo SharePoint Group
roleAssignment.RoleDefinitionBindings.Add(newPermissionLevel);

// Add the new Role Assignment to the web
rootWeb.RoleAssignments.Add(roleAssignment);

rootWeb.Close();
}
site.Close();
}

SonarQube with Jenkins Setup using Docker Images

https://funnelgarden.com/sonarqube-jenkins-docker/  https://medium.com/@hakdogan/an-end-to-end-tutorial-to-continuous-integration-and-con...