There will inevitably come a time when you're going to obtain some XML output that you need to review that would, in all honesty, be impossible to read without proper formatting. A good example would be this response from the the YouTube API that provides a list of videos that a specified user has uploaded (i.e. which would appear as follows in Notepad):
In many cases, simply copying and pasting the XML it into Visual Studio might work, but, in the off chance it doesn't, you might get something like this.
If that happens, simply hit Ctrl+k+f and the XML will be displayed in an easy-to-read format:
Wednesday, August 7, 2013
Tuesday, August 6, 2013
Calculating the number of days since an event took place using Javascript
If you're looking for a way to determine how many days have passed since a given event took place using Javascript, here is a function that will provide you with the basic functionality that you're looking for:
function calculateDaysSinceEvent(eventDateTime) { // Obtain the current date and time var todaysDateTime = new Date(); // Calculate the difference in time between today and when the event took place var diff = todaysDateTime - eventDateTime; // Convert the difference to a value that represents a day and round the value up
return Math.round(diff/(1000*60*60*24)); }
Wednesday, July 31, 2013
Javascript function for converting a datetime object to a specific format
Chances are very good that at some point during your journey with SharePoint 2013 you're going to need a javascript function that you can use for converting a datetime object into a nice, user-friendly output string for display purposes. In the code sample I'm about to provide, the javascript function will return an output string that matches the following format:
Wednesday, 7/13/2013
Here's the basic function that will give you the output presented above:
Wednesday, 7/13/2013
Here's the basic function that will give you the output presented above:
function getDateString(dateTime) { var weekday=new Array(); weekday[0]="Sunday"; weekday[1]="Monday"; weekday[2]="Tuesday"; weekday[3]="Wednesday"; weekday[4]="Thursday"; weekday[5]="Friday"; weekday[6]="Saturday"; var dayOfWeek = weekday[dateTime.getDay()]; var month = dateTime.getMonth() + 1; var day = dateTime.getDate(); var year = dateTime.getFullYear(); return dayOfWeek + ', ' + month + '/' + day + '/' + year; }
Saturday, July 27, 2013
Good solution for evaluating your web applications on various mobile devices - Ripple Emulator
If you're looking for a quick and easy solution for being able to evaluate the look and feel of your web applications or SharePoint sites across various mobile devices, the Ripple Emulator add-on for Chrome (created by the folks at tinyHippos) is definitely a great tool to have in your toolbox. Once you activate/enable the add-on against a targeted page of a site, it will allow you to quickly select a target device and instantly view the layout of your page as it would appear on that device.
For SharePoint 2013 device channels, one important note is that the user agent being posted by the emulator doesn't match the device (at least at the time of this writing); therefore, you'll want to specify the channel to use by appending the following line at the end of URL in your browser's address bar:
?DeviceChannel=DeviceUserAgent
An example would be as follows:
http://SPWebApplication/Sites/Site/default.aspx?DeviceChannel=iPhone
For SharePoint 2013 device channels, one important note is that the user agent being posted by the emulator doesn't match the device (at least at the time of this writing); therefore, you'll want to specify the channel to use by appending the following line at the end of URL in your browser's address bar:
?DeviceChannel=DeviceUserAgent
An example would be as follows:
http://SPWebApplication/Sites/Site/default.aspx?DeviceChannel=iPhone
Tuesday, July 2, 2013
Obtain all files contained under folders and subfolders within a SharePoint Document Library
If you are looking for a way to programmatically return all documents of a specific content type located within a given SharePoint Document Library regardless of whether they are contained in folders and subfolders within the given library, I've provided the following sample method that will allow you to do just that:
The key to this code being able to return all documents, including documents contained under folders and subfolders, is that I've set the ViewAttributes property to be Scope="RecursiveAll". Without this particular setting, the query would have only returned items that were located immediately under the SharePoint Document Library and would have skipped any documents contained under folders and subfolders.
private SPListItemCollection GetDocumentsByContentType(SPList docLibrary, string contentTypeName) { SPQuery query = new SPQuery(); query.ViewAttributes = "Scope=\"RecursiveAll\""; SPListItemCollection documents = null; try { query.Query = string.Format("<where><eq><fieldref name="ContentType"><value type="Text">{0}</value></fieldref></eq></where>", contentTypeName); documents = docLibrary.GetItems(query); } catch (Exception ex) { throw ex; } return documents; }
The key to this code being able to return all documents, including documents contained under folders and subfolders, is that I've set the ViewAttributes property to be Scope="RecursiveAll". Without this particular setting, the query would have only returned items that were located immediately under the SharePoint Document Library and would have skipped any documents contained under folders and subfolders.
Tuesday, May 14, 2013
How to prevent an I-Phone App that keeps Location Services enabled from draining your I-Phone's battery
Occasionally, I've run into a few I-Phone apps that have a tendency to drain your I-Phone's battery to a nearly useless state in just a few hours. Most often, this is due to the fact that the app always has Location Services (i.e. GPS) running in the background whether or not you're using the app at the moment. Here are a few quick steps you can follow to save the life of your I-Phone's battery when you're not using the offending app:
- Go to your I-Phone's Home Screen
- Touch the Settings icon
- Scroll down and then touch the General icon
- Scroll down and then touch the Restrictions item
- At this time, you'll be prompted to either (1) enter your Restrictions passcode if you've already enabled Restrictions or (2) set up a Restrictions passcode (if you haven't set one up previously, you will need to do so now)
- Enter your 4-digit Restrictions passcode
- Scroll down to the Privacy section and touch the Location Services item
- Scroll down to the item that represents the offending app and turn the value from 'ON' to 'OFF'
Once you're ready to begin your walk, run, or bike ride, simply follow these steps to re-enable the Location Services for the app:
- Go to your I-Phone's Home Screen
- Touch the Settings icon
- Scroll down and then touch the General icon
- Scroll down and then touch the Restrictions item
- Enter your 4-digit Restrictions passcode
- Scroll down to the Privacy section and touch the Location Services item
- Scroll down to the item that represents the offending app and turn the value from 'OFF' to 'ON'
Once Location Services are re-enabled for this app, it's ready to go.
With that said, the good news is that most app developers will resolve this issue once they're made aware of the situation; therefore, be sure to give them a heads up that you're encountering the problem and you're likely to receive a fix over the next few releases. Anyway, this will provide an interim solution if you have the patience to toggle Location Services for the offending app.
With that said, the good news is that most app developers will resolve this issue once they're made aware of the situation; therefore, be sure to give them a heads up that you're encountering the problem and you're likely to receive a fix over the next few releases. Anyway, this will provide an interim solution if you have the patience to toggle Location Services for the offending app.
Friday, April 12, 2013
Design Manager deployed Page Layout not displaying custom css file
I recently ran into an issue in which I was attempting to reference a custom css page within a Design Manager deployed page layout; however, I couldn't get the custom css page to load on web pages despite the fact that I was prominently referencing the css file in the proper location of the page layout's HTML file. After doing a bit of research, I finally discovered that you also need to add a special attribute to the <link> element called "ms-design-css-conversion" and set the value to "no". Here is an example of what your <link> element will look like in order for the custom css file to load properly:
<link href="MyCustomPageLayoutStyle.css" type="text/css" rel="stylesheet" ms-design-css-conversion="no" />
Also, here is a complete example that also shows you the proper location for referencing you custom css file within your custom page layout's HTML file:
<!--MS:<asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server">--> <!--CS: Start Edit Mode Panel Snippet--> <!--SPM:<%@Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>--> <!--SPM:<%@Register Tagprefix="Publishing" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>--> <!--MS:<Publishing:EditModePanel runat="server" id="editmodestyles">--> <!--MS:<SharePoint:CssRegistration name="<% $SPUrl:~sitecollection/Style Library/~language/Themable/Core Styles/editmode15.css %>" After="<% $SPUrl:~sitecollection/Style Library/~language/Themable/Core Styles/pagelayouts15.css %>" runat="server">--> <!--ME:</SharePoint:CssRegistration>--> <!--ME:</Publishing:EditModePanel>--> <!--CE: End Edit Mode Panel Snippet--> <link href="MyCustomPageLayoutStyle.css" type="text/css" rel="stylesheet" ms-design-css-conversion="no" /> <!--ME:</asp:ContentPlaceHolder>-->
Subscribe to:
Posts (Atom)