Monday, November 10, 2014

Generate Documentation For SharePoint Farm

To Generate documentation for SP farm, just follow the following steps:

- Download the this script from: https://gallery.technet.microsoft.com/office/Inventory-SharePoint-Farm-dc11fc28

- Open the SP server, then open PowerShell as administrator.

- Open downloaded script in PoweShell.


- Go to the script location to import the script


- Create directory to save reports in


- Now, if you go to C drive, you will find folder named 'Report'.

- Just execute the following command in PowerShell:
Run-FullInventory -DestinationFolder "C:\Report" -LogFilePrefix "YOURProjectName"


Now, you can go to C:\Report to view reports generated:



Then you can convert csv files to excel files to make it readable.



Note that, if you have more than one server in your farm, you should generate reports in all nodes. Because some reports like TimerJobs is depending on specific node.



Saturday, November 8, 2014

SharePoint Error: Distributed cache service is not enabled in this deployment

Sometimes you get the following error message in SP log:
"Distributed cache service is not enabled in this deployment"

To solve this issue, just enable windows service 'AppFabric Caching Service'.



Note that, if you have more than node in your farm, you should enable the service in all nodes.

Friday, July 25, 2014

iTextSharp - Make the PDF file secure

When you use iTextSharp, which is a tool used to generate PDF, using C#, you can make the PDF secure. I mean by secure, you can modify the security properities of the PDF like printing, allow modification, allow copying...etc










You have just to write the following fragment: 

            // define the document
            Document document = new Document(PageSize.A4);
            document.SetMargins(0, 0, 20, 10);

            // create memory stream to save the file
            MemoryStream ms = new MemoryStream();
            PdfWriter p = PdfWriter.GetInstance(document, ms);

            // set security properties
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            p.SetEncryption(null, encoding.GetBytes("12"), PdfWriter.AllowPrinting, 
            PdfWriter.STRENGTH40BITS);

            // open the document
            document.Open();

            // generate the document content
            document.Add(PDF_FinanceCertificate(item, p, document));

            // close the final PDF document
            document.Close();

            byte[] pdfFile = ms.ToArray();

            return pdfFile;


Note that, because we implement security issue in the PDF, the generation operation will take more time more than usual.


Thursday, January 9, 2014

How To Add Twitter (Tweet Button) To Web Page

To add twitter button to tweet your page URL just do the following:

* add this line to HTML to show tweet button:

<a href="https://twitter.com/share" class="twitter-share-button" data-url="YOUR PAGE URL" data-text="PAGE TITLE OR DESCRIPTION OF THE TWEET" data-lang="en" data-size="small" data-count="none" data-hashtags="HASHTAG YOU WANT TO TWEET FOR">TWEET</a>


* add the following script in master page or your page:

<script>!function (d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], p = /^http:/.test(d.location) ? 'http' : 'https'; if (!d.getElementById(id)) { js = d.createElement(s); js.id = id; js.src = p + '://platform.twitter.com/widgets.js'; fjs.parentNode.insertBefore(js, fjs); } }(document, 'script', 'twitter-wjs');</script>

The result will be like this:


Notes:
- URL should be published, this means you can't share localhost or internal URL if you create javascript to get the current page URL.

- You can create javascript to get the current page title.

- You can remove the section data-hashtags if you want.

- You can change the value of data-lang to your specific language like ar for Arabic language.

- You can change the value of data-size to big to show bigger icon.



Sunday, September 22, 2013

CLR To Return Full Gregorian Date By Passed Um Alqura Month And Year

In this article I will show how to create new CLR to be registered in SQL database.
This CLR includes function to convert passed Um Alqura month and year, then returns full Gregorian date.
(I mean by full, the first day of the Um Alqura date with month and year passed converted to Gregorian)


By creating new SQL server project, in visual studio 2012:


Right click on project, add new SQL CLR C# user-defined function:



The beginning of the month: 
Just add the following code:

public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static DateTime ConvertToGregorianStartDate (int Year, int Month)
    {
        System.Globalization.UmAlQuraCalendar UMQ_Calender = new System.Globalization.UmAlQuraCalendar();
        return UMQ_Calender.ToDateTime(Year, Month, 1, 0,0,0,0);
    }
}


The end of the month:
Just add the following code:

[Microsoft.SqlServer.Server.SqlFunction]
    public static DateTime ConvertToGregorianEndDate(int Year, int Month)
    {
        System.Globalization.UmAlQuraCalendar UMQ_Calender = new System.Globalization.UmAlQuraCalendar();
        DateTime firstDayOfTheMonth = UMQ_Calender.ToDateTime(Year, Month, 1, 0, 0, 0, 0);
        return firstDayOfTheMonth.AddMonths(1).AddDays(-1);
    }

Build the project and publish it to your DB.

if you execute the function created, you will get the following result:



Friday, September 20, 2013

Change Label From Persian Gulf To Arabian Gulf In Google Maps

By default, Google select Persian Gulf to be displayed as label on the gulf:

 To change it to Arabian Gulf, just add the following query string to Google map API URL:
region=SA

https://maps.googleapis.com/maps/api/js?sensor=false&language=SA&region=SA



Dealing With Google Maps - ASP.NET - Part (3)

In this article, I will show you how to store and retrieve data from SQL Server DB to Google map and vise versa.

Save data from Google map to SQL table:
Create table to store the following information:
  - Latitude
  - Logitude
  - Description of the location


our interface should be like the following:



After click SAVE button, information in text boxes should be saved to our table.




Retrieve data from SQL table to Google map:

Retrieve the data from SQL table by your own way, and define three public properties and assign value to them, those properties will called in HTML.

public string Longitude{get; set;}
public string Latitude{get; set;}
public string Desc{get; set;}

To change marker position to be like values stored in table, just change location properties from:
myCoordinates = new google.maps.LatLng( 24, 47);
to
myCoordinates = new google.maps.LatLng('<%= Latitude %>', '<%= Logitude %>');

now, we want to display location description if user click to the marker.
First change draggable property of the marker from true to false, to be read only.
Then, add the following to script:

// define new info window and assign location description
var infoWindow = new google.maps.InfoWindow({
            content: '<%= Desc %>'
        });

// add click listener to marker
google.maps.event.addListener(marker, 'click', function () {
            infoWindow.open(map, marker);
        });

and if you run the page, and click to marker, you will get the following result:


Enjoy ..