Wednesday 5 March 2014

Folder Creation in SharePoint 2010 Document Library

I have used the following code for folder creation only in document library via list item creation workflow
SPListItem CurItem = workflowProperties.Item;
SPSite MySite = new SPSite(workflowProperties.WebUrl);
SPWeb Myweb = MySite.OpenWeb();

SPDocumentLibrary spdoclibrary = (SPDocumentLibrary)Myweb.Lists["My Documents"];
Myweb.Folders.Add(workflowProperties.WebUrl + "/My%20Documents/" + CurItem["Title"].ToString());

spdoclibrary.Update();  

Another Way:-
SPList splstDoc = Myweb.Lists["My Documents"];
SPFolderCollection folderColl = splstDoc.RootFolder.SubFolders;
SPFolder newFolder = folderColl.Add(workflowProperties.WebUrl + "/My%20Documents/" + CurItem["Title"].ToString());        

I have used the following code for file along with properties creation in document library via list item creation workflow

Hashtable objhash = new Hashtable();
byte[] byt = new byte[Convert.ToInt32(FileUpload1.PostedFile.ContentLength)];
objhash.Add("custom field name", "value");
SPFolder myfolder = Myweb.GetList(workflowProperties.WebUrl + "/My%20Documents/").RootFolder;
myfolder.Files.Add("Test.txt", byt, objhash, false);           
myfolder.Update();


I have used the following code for folder along with properties creation in document library via list item creation workflow

SPFolder myfolder = Myweb.GetFolder(workflowProperties.WebUrl + "/My%20Documents/");
SPFolder spfolder = myfolder.SubFolders.Add(workflowProperties.WebUrl + "/My%20Documents/" + CurItem["Title"].ToString());
spfolder.Item["Title"] = "Aasai";
spfolder.Item["Test"] = "Aasai";
spfolder.Item.SystemUpdate(false);


Monday 6 January 2014

Object doesn’t support property or method ‘addEventListener’ SharePoint 2010 IE11

We should copy & paste the following code on your master page with in body tag.
But it should be bottom of the page.
<script language="JavaScript">
/* IE11 Fix for SP2010 */
if (typeof UserAgentInfo.strBrowser !== ‘undefined’ && !window.addEventListener) {
UserAgentInfo.strBrowser=1;
}
</script>
Example:
<body>
..
...
..
<script language="JavaScript">
/* IE11 Fix for SP2010 */
if (typeof UserAgentInfo.strBrowser !== ‘undefined’ && !window.addEventListener) {
UserAgentInfo.strBrowser=1;
}
</script>
</body>
..
..
Note: Remove & add the quote again in 'undefined'

Getting Current User & Check User in Specific Group ?

InfoPath-->Data Connection-->New-->Received Data-->SOAP Service-->
   web service url:-
   I.GetUserProfileByName:http://servername/sites/sitename/_vti_bin/UserProfileService.asmx
   II.GetUserCollectionFromGroup:http://servername/sites/sitename/_vti_bin/UserGroup.asmx
   Note:set exact group name in both place
   Change the GetUserCollectionFromGroup data connection using the following way & code:-
   Publish-->Export Source Files on your own specified location
   i.Close the Original infopath form
   ii.Open with VS2010 the GetUserCollectionFromGroup1.xsd file or maximum size of GetUserCollectionFromGroup(x).xsd file
   iii.use the XML Editor to view and edit the underlying XML schema file
   iv.

   At the top of the file, locate the following line:

<s:import namespace="http://www.w3.org/2001/XMLSchema"></s:import>

Right underneath that line, insert the following code:

<!-- Beginning of insert -->
<s:complexType name="GetUserCollectionFromGroupType">
 <s:sequence>
  <s:element minOccurs="0" maxOccurs="1" name="Users">
   <s:complexType>
    <s:sequence>
     <s:element maxOccurs="unbounded" name="User" >
      <s:complexType>
       <s:attribute name="Notes" type="s:string"></s:attribute>
       <s:attribute name="Name" type="s:string"></s:attribute>
       <s:attribute name="IsSiteAdmin" type="s:string"></s:attribute>
       <s:attribute name="Sid" type="s:string"></s:attribute>
       <s:attribute name="ID" type="s:string"></s:attribute>
       <s:attribute name="LoginName" type="s:string"></s:attribute>
       <s:attribute name="Email" type="s:string"></s:attribute>
       <s:attribute name="IsDomainGroup" type="s:string"></s:attribute>
      </s:complexType>
     </s:element>
    </s:sequence>
    </s:complexType>
  </s:element>
 </s:sequence>
</s:complexType>
<!-- End of Insert -->

[EDIT:  Please make sure there is no space in the above </s:complexType>]

Now find the following code:

<s:element name="GetUserCollectionFromGroup">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="groupName" type="s:string"></s:element>
    </s:sequence>
  </s:complexType>
</s:element>

Comment out that code by placing a <!-- before the beginning and an --> after the end.  Result should look like this:

<!--<s:element name="GetUserCollectionFromGroup">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="groupName" type="s:string"></s:element>
    </s:sequence>
  </s:complexType>
</s:element>-->

Right underneath that commented out code, insert the following code:

<!-- Beginning of Insert -->
<s:element name="GetUserCollectionFromGroup" type="tns:GetUserCollectionFromGroupType" />
<!-- End of Insert -->

Save and close the file

v.Go back to the folder where you saved those Source Files to.  Find the file "manifest.xsf" and
RIGHT-click the file and choose "Design".
This will open your InfoPath file back up.  Click SAVE AS and save as a new .xsn file.

Note:
Everything you have done after that if you are getting the following errors:-

************
Error 1:
An error occurred while trying to connect to a Web service.

An entry has been added to the Windows event log of the server.
Log ID:5566
---------------
Error 2:
The following query failed: GetUserCollectionFromGroup (User: SHAREPOINT3\spuser1, Form Name: SOR, IP: , Connection Target: , Request: http://sharepoint/_layouts/FormServer.aspx?XmlLocation=/sites/agc/SOR/131224063651.xml&ClientInstalled=false&Source=http://sharepoint/sites/agc/SOR/Forms/AllItems.aspx&DefaultItemOpen=1, Form ID: urn:schemas-microsoft-com:office:infopath:SOR:-myXSD-2013-12-03T05-15-35 Type: DataAdapterException, Exception Message: The remote server returned an error: (401) Unauthorized.
The remote server returned an error: (401) Unauthorized.)
****************
Solution:
You should check & do the following steps:-

1.IIS-->Authentication-->ASP.NET Impersonation Enabled. ( try with disabled also, if it is already enabled)
2.RUN-->regedit-->HKEY_LOCAL_MACHINE-->SYSTEM-->CurrentControlSet-->Control-->
        Lsa(Right click)-->
  Create new DWORD(32 bit) value or QWORD(64 bit) value with the name as a "DisableLoopbackCheck"
  Then edit it give value as a "1".
3.Check Who can view the membership of the group?   
  "Everyone" 
Ref:

Tuesday 28 May 2013

How to Add fields(Columns) in list definition ? Part III

2. We should add the following line in list definition elements.xml then change the content type id as a concat 0x0100 with new guid.(note: removed '{}' & '-') and then fieldref id is your own created field(column) id.

<ContentType ID="0x0100560CF9639C39489B845C07ED8116F6F1" Name="CutomAsaiType" Group="Custom CT" Inherits="FALSE" Description="">
    <FieldRefs>
      <FieldRef ID="{9FDF6527-1072-4751-8B15-84CA97AE7CBA}"/>
    </FieldRefs>
  </ContentType>

3. Replacing the following code in schema.xml
<ContentTypes>
      <ContentTypeRef ID="0x01">
        <Folder TargetName="Item" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x0120" />
    </ContentTypes>
  With

<ContentTypes >
      <ContentTypeRef ID="0x0100560CF9639C39489B845C07ED8116F6F1">
      </ContentTypeRef>
    </ContentTypes>
and then change the contenttyperef id as your own list definition content type id.



4. Add the created field in view, the following way:-

<FieldRef Name="Name"></FieldRef>

 


Now you can able to deploy successfully and then you can see the list with field on the site.

If it is getting error like "A duplicate field name "Name" was found",
Solution1: You should change the field Name on list definition elements.xml, schema.xml & view and then add the same as a static name in list definition element.xml & schema.xml.

After that you are getting same error once agin,
Follow the Solution1 and then change field id as new guid.

There after you are getting error, please let me know.