Wednesday, 17 April 2013

Failed to instantiate file "ContentQueryMain.xsl" from module "XSLStyleSheets": The specified list does not exist.


1)open SharePoint designer 2010
2)all files->rename "Style Library"
3)create a new doc library with name "Style Library"
4)Refresh the page

Tuesday, 16 April 2013

Error occoured in deployment step 'activate feature'.Attempted to perform an unauthorized operation


This error you may find while deploying your SharePoint solution. To fix this issue you just need to make sure you have administrator permission to the site collection.

here are steps:

1)go to central admin
2)Change Site collection adinistrator
3)Add system logged in user name as primary or secondary site administrator
4)Deploy solution

We will find you solution get deployed.

Thursday, 5 July 2012

"<nativehr>0x80071779</nativehr><nativestack></nativestack>The file is locked for exclusive use by Domain\User."

Sometimes you may land up in this trouble when try to update an item in  document library after editing the file attached to it.
this exception clearly says "the file has been locked".I have got 2 solutions For it
1)Impersonation
2)Release Lock


First Option(this will allow you to update but lock is not released)
-------------
1)try to impersonate to application identity
   Dim systemAccountToken As SPUserToken = SPContext.Current.Site.SystemAccount.UserToken
        Using site1 As New SPSite(SPContext.Current.Site.ID, systemAccountToken)
            Using web1 As SPWeb = site1.OpenWeb(SPContext.Current.Web.ID)

2) Get a reference to list and then to item which you want to update.
3) Make changes
4) Finally item.SystemUpdate()


Second Option(permanently will release the lock)
--------------------------------------------------
1)Get the reference to the item you want to update(normal way,without impersonation)
2) Check if file is still locked
3) Release Lock
4) Then make changes whatever you want to do.
 e,g
               Dim lockedfile As SPFile = itm.File  'gets the file associated with the item
                    If lockedfile.LockType <> SPFile.SPLockType.None Then  'check if file is still locked
                        lockedfile.ReleaseLock(lockedfile.LockId)  'releases lock
                   End If


I hope this will help someone.Any suggestions,always welcome :)


Thursday, 12 April 2012

code to avoid commas inside double quotes while reading csv files

Recently i was asked to read from a .csv file and populate metadata into sharepoint list items.There i stumbled upon a annoying thing that is values separated by commas inside double quotes which should be considered as asingle element
which means i had to write code to ignore values separeted commas inside double quotes and this is how did that.i hope it will help others and if somebody knows better way of doing it,then share the code with me as well

Here it is:
read line by line from csv file
  line = fs.ReadLine()

 Dim Array(30) As String
                Dim splitter() As Char = {","}
                Dim chars As Char() = line.ToCharArray()
                Dim j As Integer = 0

                Dim flag As Boolean = False
                Dim word As Char() = Nothing
                For i = 0 To chars.Length - 1
                    If Not flag Then
                        If chars(i) = ControlChars.Quote Then
                            flag = True
                            Continue For
                        End If
                        If chars(i) <> "," And i <> chars.Length - 1 Then
                            If Not flag Then
                                word += chars(i)
                            End If
                        ElseIf i = chars.Length - 1 Then
                            Try
                                word += chars(i)
                                Array(j) = word
                            Catch ex As Exception
                            End Try
                        Else
                            Try
                                Array(j) = word
                                word = Nothing
                            Catch ex As Exception

                            End Try
                            j += 1
                        End If
                    Else

                        If (i + 1) < chars.Length - 1 And chars(i + 1) <> ControlChars.Quote Then
                            word += chars(i)
                            Continue For
                        Else
                            If chars(i + 1) = ControlChars.Quote Then
                                word += chars(i)
                            End If
                            flag = False
                            i += 2
                        End If
                        Try
                            Array(j) = word
                            word = Nothing
                        Catch ex As Exception
                            'Array(j) = ""
                        End Try
                        j += 1
                    End If
                Next

After this start populating like   Dim names As String = Array(2) etc

thank you

Wednesday, 11 April 2012

Requiredfield validation on people picker

here are the few steps required for people picker validation in sharepoint.

1)press F12 and highlight the textarea of the people picker and copy the id
2)dont use (document.getElementById('<%= peoplepickerid.ClientID %>');) ,it wont work
3) then  create a javascript function


function callPostBack() {
       
        var a = document.getElementById('<%= ApprovingAuthorityPicker.ClientID %>'); //wont work

        var b=document.getElementById("ctl00_m_g_efabbd0f_b6f5_492c_92f8_18063b505623_ctl00_ApprovingAuthorityPicker_downlevelTextBox");
        if (b.value != "")
            return true;
        else
        {
        alert("Required field");
            return false;
    }

4)"ctl00_m_g_efabbd0f_b6f5_492c_92f8_18063b505623_ctl00_ApprovingAuthorityPicker_downlevelTextBox" is the copied id from step 1

5)call the javascript function on button click i,e

 <asp:Button ID="btnTopicSubmit" runat="server" Text="Save" OnClick="btnTopicSubmit_Click"  ValidationGroup="g2"
                                                CssClass="nav_newsmall" OnClientClick="return callPostBack();" />

6)check again and enjoy.

Thanks


Saturday, 21 January 2012

Code to delete a Folder,all the Sub Folders and also files inside Subfolders and the root folder and The Root Folder in .Net




Create a console application.Then in  code behind put this code and enjoy :)
---------------------------------------------------------------------------
Imports System.Configuration
Imports System.Data
Imports System.IO
Imports System.IO.FileStream


Module Module1
    Sub Main()

        Dim line As String = String.Empty
        Dim file As StreamReader = Nothing
        Dim content As String = String.Empty
        Dim strFileSize As String = ""
        Dim root As New DirectoryInfo(ConfigurationManager.AppSettings("DirURL"))
        Dim arFi As IO.FileInfo() = root.GetFiles()
        For Each f1 As FileInfo In arFi
            f1.Delete()
        Next
        childDirectories(root.GetDirectories())
        If root.GetDirectories.Count = 0 And root.GetFiles.Count = 0 Then
            root.Delete()
        End If

    End Sub

    Public Sub childDirectories(ByVal root As DirectoryInfo())
        For Each child As DirectoryInfo In root
            FindAndDeleteFiles(child)
            childDirectories(child.GetDirectories()) 'recursion
            If child.GetDirectories.Count = 0 And child.GetFiles.Count = 0 Then
                child.Delete()
            End If
        Next
    End Sub
    Public Sub FindAndDeleteFiles(ByVal dir As DirectoryInfo)
        Dim arFi As IO.FileInfo() = dir.GetFiles()
        For Each f1 As FileInfo In arFi
            f1.Delete()
        Next

    End Sub
End Module


---------------------------------------------------
Add a Configuration file to your solution,then  add appsettings under <configuration> section
------------------------------------------------------------

 <appSettings>
        <add key="DirUrl" value="give full path of the root folder you want to delete"/>
    </appSettings>

----------------------------------------
press F5  and get ur folders deleted.