Friday, September 5, 2014

SharePoint 2013 - Get Add Remove - My Tags or SocialTag using javascript service call


SharePoint 2013 - Get Add Remove - My Tags - SocialTag - avaliable in socialdataframe.aspx ( Tags and Note Board ) - using service call  /_vti_bin/socialdatainternalservice.json 

GetTags:
$.ajax({
                                                           url: "/_api/contextinfo",
                                                           type: "POST",
                                                           contentType: "application/x-www-url-encoded",
                                                           dataType: "json",
                                                           headers: { "Accept": "application/json; odata=verbose", },
                                                           success: function (data) {
                                                               if (data.d) {
                                                                   var digest = data.d.GetContextWebInformation.FormDigestValue;
alert(digest);
                                                                   $.ajax({
                url: "/_vti_bin/socialdatainternalservice.json/GetSocialTagInternal",
                dataType: 'json',
                type: 'POST',
                data: '{"targetPage":"http://vddp23g-6c4153b:100/us/spc-do-01/eFileLibrary/PX230230","maximumItemsToReturn":"12"}',
                contentType: 'application/json; charset=utf-8',
                headers: {
                                                                           "accept": "application/json;odata=verbose",
                                                                           "X-RequestDigest": digest,
                                                                       },
                success: function (data) {
alert('success');
                     console.log(JSON.stringify(data));
                },
                error: function (err) {

                    alert(JSON.stringify(err));
                }
            });
                                                               }
                                                           },
                                                           error: function (err) {
                                                               alert(JSON.stringify(err));
                                                           }
                                                       });
                                                      
                                                       }


AddTag:
(Replace following in the above ajax call)
url: "/_vti_bin/socialdatainternalservice.json/ManageTagInternal",
                dataType: 'json',
                type: 'POST',
                data: '{"targetPage":"","title":"","changes":[{"ChangeType":0,"TermID":"d5f86d42-4f82-4574-9318-4559b4f5d3a9","Term":"spotlight","IsPrivate":false}],"maximumItemsToReturn":"12"}',


RemoveTag:
(Replace following in the above ajax call)
url: "/_vti_bin/socialdatainternalservice.json/ManageTagInternal",
                dataType: 'json',
                type: 'POST',
                data: '{"targetPage":"","title":"","changes":[{"ChangeType":2,"TermID":"350ba065-5119-4b9a-8d07-6e74d603d939","Term":"tamarind","IsPrivate":false}],"maximumItemsToReturn":"12"}',

Saturday, June 22, 2013

SharePoint 2013 : enable the Developer Dashboard from PowerShell

To enable the Developer Dashboard from PowerShell, you can use the following lines of script; just
make sure to turn it off when you finish using it in production:

$contentService = ([Microsoft.SharePoint.Administration.SPWebService]::
ContentService)
$devDashboardSettings =$contentService .DeveloperDashboardSettings
$devDashboardSettings.DisplayLevel =
[Microsoft.SharePoint.Administration.SPDeveloperDashboardLevel]::On
$devDashboardSettings.Update()


Note: the Developer Dashboard is a farm-wide setting

SharePoint 2013 : enable advanced debugging in your Visual Studio

Because SharePoint builds on many layers below it, such as Windows Communications
Framework (WCF), you may want to enable advanced debugging in your Visual Studio environment.

To do this, go into the Registry Editor, find [HKEY_CURRENT_USER\Software\Microsoft\
VisualStudio\10.0\SharePointTools], and change the DWORD value for EnableDiagnostics
from 0 to 1. If the DWORD value does not exist, create it as a new DWORD value. 


When you set this value, you see in the output window in the Visual Studio all the information that Visual Studio gets form SharePoint via the stack trace.

Custom templates not appearing on Create List or Libraries page in SharePoint site

If the custom list templates are not appearing in the Create page of your SharePoint site. Activate the Enterprise and Publishing feature of the site, then you will get them.

Saturday, June 15, 2013

Byte array - OutOfMemory exception on large file download - fix



Issue:
‘Byte’ array length has limitations. Here we found max supported to be around 1.3 GB (varies based on processor and available RAM). If length is set beyond, it throws an ‘OutOfMemory’ exception.

Fix:
Check if file exceeds 1GB, if so a functionality that splits the ‘file stream’ in chunks of ‘Byte’ array which is then fed to the ‘Response.BinaryWrite’ sequentially is executed. Else you can also use 'httpResponse.TransmitFile' option.

Code:

                WebClient client = new WebClient();
                client.DownloadFile(url, path);

                CustomLogger.WriteInfo("Download", "Page_Load", "Completed 'client.DownloadFile'");
                fileStream = new FileStream(path, FileMode.Open);
                int fileLength = (int)fileStream.Length;
                CustomLogger.WriteInfo("Download", "Page_Load", "FileStreamSize:" + fileLength.ToString());

                httpResponse.ClearHeaders();
                httpResponse.Clear();

                httpResponse.ContentType = "application/octet-stream";
                httpResponse.AddHeader("Content-Transfer-Encoding", "binary");
                httpResponse.AddHeader("Content-Disposition", "attachment;filename=\"" + filename + "\"");
                httpResponse.AddHeader("Content-Length", fileLength.ToString());

                //Handling Large files
                if (fileLength >= Constant.MaxFileSize) //MaxFileSize - 1073741824 or 1Gb
                {
                    CustomLogger.WriteInfo("Download", "Page_Load", "BinaryWrite multiple instance");
                    int bufferSize = Constant.MaxFileSize;
                    long filePos = fileStream.Length;
                    long mod = filePos / bufferSize;
                    long val = default(long);


                    for (int j = 0; j <= mod; j++)
                    {
                        byte[] buffer = null;
                        int bytesToRead = bufferSize;
                        if (j == mod)
                        {
                            int minusVal = default(int);
                            if (val == 0)
                                minusVal = (int)val + bytesToRead;
                            else
                                minusVal = (int)val;

                            long subVal = filePos - (minusVal);
                            buffer = new byte[(int)subVal];
                            bytesToRead = (int)subVal;
                        }
                        else
                        {
                            buffer = new byte[bufferSize];
                        }

                        val = fileStream.Seek(0, SeekOrigin.Current);
                        int bytesRead = fileStream.Read(buffer, 0, bytesToRead);
                        httpResponse.BinaryWrite(buffer);
                        httpResponse.Flush();
                    }
                }
                else
                {
                    CustomLogger.WriteInfo("Download", "Page_Load", "BinaryWrite single instance");
                    byte[] fl = default(byte[]);
                    fl = new byte[fileStream.Length];
                    fileStream.Read(fl, 0, fileLength);
                    httpResponse.BinaryWrite(fl);
                    httpResponse.Flush();
                }

                httpResponse.End();

Override EnableEventValidation in c#

         ///
        /// Fix for Enableeventvalidation
        ///

        public override bool EnableEventValidation
        {
            get
            {
                return false;
            }
            set
            {
                base.EnableEventValidation = false;
            }
        }

Tuesday, November 27, 2012

Wrong Sharepoint lookup value

Issue:


You might not get an error but you might end up with a wrong lookup value.

Effect:

During data migration when associating source item lookup value to the target item lookup value directly. Please ensure that the lookup Id is the same for the source lookup value and the target lookup value, as it assigns whatever value is associated with the lookup Id got from the target side. This is fine as long as both the side’s lookup value has the same Lookup Id if not you will end up with a wrong value.

Cause:

As each lookup value’s Id is auto generated from its lookup master list. There are chances of id mismatch between the source side and the target side when items are deleted and entered repeatedly without uniformity.

Caution:

So please check your source and destination master lookup lists value-id association if you are facing a similar issue.

Code logic solution for above scenario:

Get the lookup value from the source item and query the master lookup list associated with the current lookup field and get the item id and associate it to your SPLookFieldValue.