8/17/2011

PowerShell to the Rescue… SharePoint User has no EMail address

 

I’m working with a SharePoint farm where the AD synchronization is not working, and we had a user who for some strange reason did not have an email address in SharePoint and could not get alerts. So while we are working out the AD problem, here’s how I quickly added an email address for this user:

$user = Get-SPUser  domain\username -web http://yourserver/sites/yoursitecollection

`check to see if they have an email address
$user.Email

`set an email address
$user.Email = "user@domain.com"
$user.Update()

Simple… and quick. But you will need to do this for each site collection the user has access to.

 

More on Get-SPUser:  http://technet.microsoft.com/en-us/library/ff607580.aspx

More on the SPUser object that’s returned by Get-SPUser: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser.aspx

.More on all of the properties and members of SPUser: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spuser_members.aspx

 

 

.

8/15/2011

Searching and Auditing SharePoint with PowerShell

 

Last week I gave a presentation to the Dayton SharePoint user group on using PowerShell to search and audit SharePoint. In this article, and one or two follow ups I’ll expand on that presentation.

So what’s here?

  • An overview of permissions needed to use PowerShell with SharePoint
  • How to use PowerShell with both SharePoint 2007 and 2010
  • The SPFarm object and a few of its properties
  • The SPService object

 

Goals:

  • Find info that cannot be found with the out of the box tools
  • Find info that can not be conveniently found with the out of the box tools
  • Collect data for reports
  • Do nothing that is not undoable
  • Do nothing (or as little as possible) that impacts server performance

In this article we are not:

  • Doing administration
  • Doing installs
  • Doing Backups and Restores

PowerShell can do all of this, but those are for other sessions (and other presentors)

 

Permissions:


Not everyone who can start PowerShell can access SharePoint data using the SharePoint 2010 PowerShell cmdlets! PowerShell does not avoid SharePoint security, and actually adds an additional requirement or two.

  • You can use the “setup account” that was used to install SharePoint as it has the rights listed below (but this is not the best practice!)
  • You must be a member of the SQL SharePoint_Shell_Access role
  • You must be a member of the WSS_Admin_WPG local security group on each server
  • You can configure both of the above using one SharePoint PowerShell cmdlet:
        Add-SPShellAdmin –Username “domain/user” -Database “databasename

For SharePoint 2007, just think about which permissions would be needed to otherwise get to the desired content. You will need the same permissions when using PowerShell. Access to the Farm object will require admin permissions. Access to a Site Collection will require Site Collection Administrator, Site Owner, or for some data, Visitor permissions.

 

Memory Management (and possible “manglement!)

 

First the bad news: You have to manage memory. If you don’t, you can crash your SharePoint server by creating objects that are not immediately disposed of. As you drill down into the SharePoint hierarchy you can potentially create thousands of objects.

Different PowerShells, different memory defaults

If running a PowerShell other than the SharePoint 2010 Management Shell, such as the Integrated Scripting Environment (ISE), each command line (each press of the Enter key) runs on a different thread.

         $site = Get-SPSite http://intranet/sites.training
         $site.Dispose()

When the above is run in the ISE the $site object is not been immediately disposed as the request was made on a different thread.

Starting the SharePoint 2010 Management Shell runs this:
      $ver = $host | select version
      if ($ver.Version.Major -gt 1)
          { $Host.Runspace.ThreadOptions = "ReuseThread“ }
      Add-PsSnapin Microsoft.SharePoint.PowerShell
      Set-location $home"

“ReuseThread” causes all commands to now run in the same thread.

 

Memory tools

 

If you would like to track the memory being used by PowerShell you can check the running processes on your PC. PowerShell includes a cmdlet, Get-Process (gps for short) just for this, and it also keeps track of its own process ID in a variable named $PID. You can check the current memory being used with this command:

      gps -id $pid

 

Here’s a sample test:

      `create 100 subsites
      gps -id $pid; 
      for ($i=0; $i -lt 100; $i++) 
      { 
        $s = new-spweb http://intranet/sites/training/PS$i ; 
      } 
      gps -id $pid;

 

Here’s a sample test with dispose:

      `create 100 subsites 
      gps -id $pid; 
      for ($i=0; $i -lt 100; $i++) 
      { 
        $s = new-spweb http://intranet/sites/training/PS$i ;
        $s.dispose(); 
      } 
      gps -id $pid;

 

Sometimes you need to force the garbage collection process if you need to immediately free up RAM. Do not do this excessively as it will be very slow. That said, the following is not best practice!

      `create 100 subsites 
      gps -id $pid; 
      for ($i=0; $i -lt 100; $i++) 
      { 
        $s = new-spweb http://intranet/sites/training/PS$i ;
        $s.dispose(); 
        [System.GC]::Collect());

      } 
      gps -id $pid;

 

Memory - helper functions

If you plan to do much memory usage testing then you may want to create a function or two to save some typing:

PowerShell Process memory:
      function psm
      {
        (Get-Process $pid).PrivateMemorySize/1024/1024
      }

 

Run the garbage collector:
      function cg
      {
        [System.GC]::Collect()
      }

 

Is PowerShell just for SharePoint 2010? Or will it work in SharePoint 2007?

 

SharePoint 2010 includes nearly 600 PowerShell cmdlets. With these you can quickly get a hold of common SharePoint objects with a simple command. Here is how you can get a Site Collection object in one line:

      $site = Get-SPSite http://intranet/sites/training

 

There are no SharePoint PowerShell cmdlets for SharePoint 2007! But that is not too much of a problem as PowerShell can directly access DLLs, including the SharePoint DLLs.

First you will need to load the SharePoint DLL:

      [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

Then you can use the SharePoint API to create SharePoint objects such as a Site Collection object. The following creates the exact same object as the cmdlet above, and it will work in both 2007 and 2010.

$site = New-Object Microsoft.SharePoint.SPSite(“http://intranet/sites/training”)

 

The SharePoint Hierarchy

 

When looking for a single object in SharePoint (site, list, item, etc) you will often be able to use a single PowerShell cmdlet or API object. But when you want to find all Word documents in all libraries in all site collections in all sites in all web applications, then you will need to drill down through the SharePoint object Hierarchy. Here are the primary objects we will be working with in these articles:

 

SPFarm (the config database)

  SPWebService (Excel services, etc)

    SPWebApplication (IIS app plus a SQL DB)

      SPSite (Site collection)

        SPWeb (a single site)

          SPList & SPLibrary (a single list)

            SPListItem (a single list item)

              SPField (a single property)

 

Each of these objects have their own collections of properties that we can browse through using PowerShell.

 

The Farm

 

As a start, let’s take a look at the top most object in the SharePoint hierarchy, the SPFarm object. Note that the Farm is the Config database, not the collection of physical servers. In fact, the collection of server objects is just one of many properties of the Farm.

For SP 2010:
      Get-SPFarm returns the farm object    (actually the SharePoint Config database)

Or for SP 2007:
      $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local

Get the farm:
      $farm = Get-SPFarm

Get the version:
      $farm.BuildVersion              or (Get-SPFarm).BuildVersion

Get the list of servers:
      $farm.Servers                       or Get-SPServer

Get a list of installed Features
      $farm.FeatureDefinitions | sort scope                  or Get-SPFeature

Get a list of installed Solutions
      $farm.Solutions                     or Get-SPSolution

 

Get a list of installed products (or SKUs)

       $farm.Products

This returns a list of GUIDs of the installed products.

Value Product
84902853-59F6-4B20-BC7C-DE4F419FEFAD Project Server 2010 Trial
ED21638F-97FF-4A65-AD9B-6889B93065E2 Project Server 2010
BC4C1C97-9013-4033-A0DD-9DC9E6D6C887 Search Server 2010 Trial
08460AA2-A176-442C-BDCA-26928704D80B Search Server 2010
BEED1F75-C398-4447-AEF1-E66E1F0DF91E SharePoint Foundation 2010
1328E89E-7EC8-4F7E-809E-7E945796E511 Search Server Express 2010
B2C0B444-3914-4ACB-A0B8-7CF50A8F7AA0 SharePoint Server 2010 Standard Trial
3FDFBCC8-B3E4-4482-91FA-122C6432805C SharePoint Server 2010 Standard
88BED06D-8C6B-4E62-AB01-546D6005FE97 SharePoint Server 2010 Enterprise Trial
D5595F62-449B-4061-B0B2-0CBAD410BB51 SharePoint Server 2010 Enterprise
926E4E17-087B-47D1-8BD7-91A394BC6196 Office Web Applications 2010


More info here:

http://blogs.technet.com/b/vedant/archive/2010/10/05/detecting-installed-sku-of-sharepoint-2010-and-upgrading-editions.aspx

 

 

The Services

 

While looking at the SPFarm object let’s take a look at the SPServices object. SharePoint 2010 seems to have an endless list of services. Which are installed on your farm?

SharePoint 2010 does not have a “Get-SPServices” cmdlet, so we will have to get the services object SPFarm object.

      $farm = Get-SPFarm    (or   $farm = [Microsoft.SharePoint.Administration.SPFarm]::Local )

      $farm.Services | select TypeName

Note that the web applications (SPWebApplication) are a special kind “service” (Microsoft SharePoint Foundation Web Application) and can be retrieved using Get-SPWebApplication or by looping through all of the SPService objects and checking the type of service.

 

Next

 

In the next installment we will start looking at, and start exploring, the “everyday” objects such as Site Collections, Webs, Items and Users.

  • Get a list of all site collections
  • Get a list of all sites of type “abc” (blog, Team Site, etc)
  • Get a list of all groups and their users
  • Get a list of all users
  • Get a list of all permissions
  • Get a list of all lists that use Content Type “abc”
  • and a few more...

.

8/08/2011

Speaking at the Dayton SharePoint User Group on Tuesday

 

I will be speaking Tuesday evening, August 9, 2011, at the Dayton SharePoint User Group. The topic will on “Finding Stuff in SharePoint using PowerShell” (formally “Using PowerShell to Audit SharePoint”).

http://www.dayspug.org/

 

Some of the topics covered will include:

  • How to use PowerShell to get a list of all
    • sites in a farm
    • lists that use a selected Content Type
    • sites based on a selected template (blogs, etc)
    • all sites/lists/items with broken inheritance (unique permissions)
    • all Site Collection Administrators from all site collections
    • all installed Solutions
    • all installed Features
    • all products installed (SP edition, Project Server, etc)
    • all users and groups who access to a site
    • and many more

I also have a few donations for the door prize giveaways, including a couple copies of my book SharePoint 2007 & 2010 Customization for the Site Owner, and from MAX Technical Training, tickets to a sporting event and some training discounts!

 

So stop on out!  

Directions here: http://www.dayspug.org 

 

.

7/29/2011

Cincinnati SharePoint User Group Meeting Thursday 8/4/11

 

http://www.CincinnatiSPUG.org/

 

Meeting date:     Aug 4, 2011, Thursday
Time:                   6:00 – 8:00 pm.
Where:                Max Technical Training, 4900 Parkway Dr. #160 Mason, OH.  
                             Directions  http://www.maxtrain.com/directions

 

Schedule:
6:00 – 6:25 - Socials and Networking - No Registration required
6:25 – 6:30 - Introduction of Agenda and Speakers
6:30 – 8:00 – Presentation

 

Session Title: “Caching-In” for SharePoint Performance

Abstract: Caching is a critical variable in the SharePoint scalability and performance equation, but it’s one that’s oftentimes misunderstood or dismissed as being needed only in Internet-facing scenarios.  In this session, we’ll build an understanding of the caching options that exist within the SharePoint platform and how they can be leveraged to inject some pep into most SharePoint sites.  We’ll also cover some sample scenarios, caching pitfalls, and watch-outs that every administrator should know.

Speaker bio: Sean P. McDonough
Bio: Sean is a Product Manager for SharePoint Products at Idera, a Microsoft gold certified partner and creator of tools for SharePoint, SQL Server, and PowerShell.  As a consultant, Sean has worked with a number of Fortune 500 companies to architect, implement, troubleshoot, tune, and customize their SharePoint environments. Sean is an MCPD, an MCTS, and the co-author of both the “SharePoint 2007 Disaster Recovery Guide” and the “SharePoint 2010 Disaster Recovery Guide”.

 

.

7/24/2011

SharePoint 2010: Finding a Unique HTML ID Using the $get Function

 

ID=…

 

Go look up the definition of the HTML ID attribute. The standards say that the ID must be unique in the page. No two elements should share the same ID.  SharePoint frequently breaks this rule. If you have two web parts of the same, or similar, type, they will often each have elements with the same ID. As an example, any web part in 2010 that displays a document icon (Word, Excel, etc) has an anchor tag like this one: <a id="diidSortDocIcon". As a result, the DOM method getElementById will not work as you might hope. While methods like getElementsByTagName (note the “s”) will return a collection of elements, getElementById (note no “s”) either returns null or the first element found with that ID. Bottom line, unless you loop through all of the elements in the page and check each one for that ID, you will only be able to retrieve the first element that uses that ID.

 

$get

To deal with this problem, Microsoft added a function to SharePoint with the name $get(). (Actually I believe this $get is part of the AJAX client side libraries.) This function, when passed a single parameter, will return the first element with that ID in the document. When called with an object as the second parameter, it searches all of the child nodes of that object for an element with that ID and returns the first one it finds.

Here’s what the function code looks like when displayed from an alert():

    image

 

$get("IdToFind",ElementToSearchWithin)

The code displayed above is kind of interesting. If the second parameter is not supplied, then the code just uses getElementById and returns a null or a the single element. If the second parameter is supplied, then the code finds all of the child nodes of the the element listed as the second parameter. It then loops through all of the child elements until it finds one with the ID in the first parameter. (if (a.id == f)

 

As an example, the following will display the innerHTML of the element with the ID of “diidSortDocIcon”, but only if it is found in the element with the ID of “MSOZoneCell_WebPartWPQ6”.


var
mywebpart = document.getElementById(“MSOZoneCell_WebPartWPQ6”) $get("diidSortDocIcon", mywebpart).innerHTML

 

This could also be written as:

$get("diidSortDocIcon",$get("MSOZoneCell_WebPartWPQ6")).innerHTML

 

$get(), just another little tool for your SharePoint customization toolbox!

 

.

7/19/2011

SharePoint: Changing the “Add New” Icon

 

I just got an interesting question on the “Change the “Add New” message for a web part” article about replacing the icon in the Add New Item area of a web part. As CSS does not let you change the attributes of an element (i.e. “src=”), the solution is a bit of a trick.

The before and the after for SharePoint 2007:

image  image

And in 2010:

image    image

The CSS below first hides the existing icon, and then adds a background image to the anchor (“A”) tag. As this results in the text being displayed over the icon, the CSS also needs to add a little padding to move the text over a bit.

The CSS for both 2007 and 2010

Add just before the </head> tag in the master page or in a content editor web part on a single page.

<style>

/*  hide the existing image  */
.ms-addnew img
{
  display:none;
}

/*  add a background image  */
.ms-addnew a
{
  background:url(_layouts/images/titlegraphic.gif) no-repeat;
  padding-left: 25pt;
}

</style>

 

 

.

7/18/2011

SharePoint Saturday Columbus 2011!

 

Join me and thirty other speakers for a free day of SharePoint learning on Saturday August 20th, 2011.

 

Go and check out the list of speakers and register!  It’s FREE!

   http://www.sharepointsaturday.org/columbus/default.aspx

Stolen right from their web site:

Join SharePoint architects, developers, and other professionals that work with SharePoint 2007 and 2010 for SharePoint Saturday Columbus event.  SharePoint Saturday is an educational, informative & lively day filled with sessions from respected SharePoint professionals & MVPs, covering a wide variety of SharePoint-orientated topics.  SharePoint Saturday is FREE, open to the public and is your local chance to immerse yourself in SharePoint!

 

I will be speaking on a subject that I’ve always enjoyed (and what much of this blog is about), “SharePoint 2007 and 2010 Customization for Site Owners”.

This session will get you, the SharePoint Site Owner, started in customizing your SharePoint site. It is not a programming session, but does include some JavaScript coding. It is not a graphics design session, but does include some Cascading Style Sheets. It is not a SharePoint Designer session, but it will make use of it. And nothing requires access to the SharePoint servers.

While the session is for the SharePoint Site Owner, it's also for the developer who does not want to "reinvent the wheel". All you need to apply what you learn here are basic SharePoint skills, how to copy and paste and some puzzle solving skills.

And as I have just released a book on the same topic, I’ll be brining a few copies to give away! If you don’t want to wait until August, you can get it at Amazon (with free shipping) or until the end of July, directly from the publisher with a 25% discount (with this code: 77ULP6VH).

 

 

.

7/15/2011

SharePoint 2007: Moving the View Dropdown for Wide Lists

 

One of the annoying “features” of SharePoint 2007 is how the View dropdown gets pushed off of the page when working with list views with many columns.

 

Left part of the page:

image

One scroll to the right:

      image

Two scrolls to the right and we can now find the view menu:

            image

 

What would be nicer would be a View menu just to the right of the other toolbar buttons.

image

 

All we need to do is write a little JavaScript to find the toolbar TABLE and adjust the column widths.

Steps for a single view page:

  1. Display the list’s view page
  2. Click Site Actions, Edit Page
  3. Add a Content Editor Web Part and move it to the bottom of the page (below the list’s web part)
  4. Edit the Content Editor Web Part, click the Content Editor button and paste in the following JavaScript
  5. Save everything and test!

Steps for all lists, pages and views:

  1. Open SharePoint Designer and open your site
  2. Open your master page (typically default.master)
  3. Scroll to the bottom of the page and click just before the </body> tag
  4. Paste the following JavaScript
  5. Save everything and test!

 

<script>
// from TechTrainingNotes.blogspot.com
// find all tables var x = document.getElementsByTagName("table"); for (var i=0;i<x.length;i++) { // find the table with this class if (x[i].className=="ms-menutoolbar") { // change the widths of all of the cells to 0 for (var j=0; j<x[i].rows[0].cells.length;j++) { x[i].rows[0].cells[j].style.width="0" } // change the width of the last column x[i].rows[0].cells[j-1].style.width="100%" } } </script>

I tried to solve this little problem by using CSS instead of JavaScript. I got close, but ended up with an empty cell at the end of the row. So, let me know if you find a CSS solution.

<style>

.ms-listheaderlabel
{
  width:100%
}
.ms-menutoolbar
{
  width:0;
}
</style>

 

.

6/24/2011

Book’s done!

 

imageI thought I’d write a little book. I had two weeks of vacation time… Take some of the better stuff from the blog, clean it up and polish it, and may be have 250 pages of content…

Now ten months later I have 400 pages of content and enough stuff for a second book. I can’t let go of this thing! I finally did one final pass of edits and uploaded it to the publisher!

So what did I end up with? This:

  • 401 pages
  • 304 screen captures
  • 83,338 words (including sample code)
  • 3879 lines of sample JavaScript, jQuery and CSS
  • 504,721 characters
  • a ridiculous number of hours
  • At least (I have not counted yet) 75 customizations and tricks that will work in WSS, MOSS, SharePoint Foundation and SharePoint Server. And most should work in Office 365.

 

Book’s done!

The family is relieved… they have not seen me much at all lately. Work, study, teach and then go write - repeat.

Now I can:

  • take some time off
  • fly some model airplanes
  • take a ride in a Tri-Motor Ford with my sons (did that today!) (may have to go back on Sunday and do it again)
  • start another book……………

 

Book’s done!

If you like the articles in this blog, then you should really like the book. More tricks and tips. More details on each one. Both 2007 and 2010 versions for almost every example.

You can order it here today: https://www.createspace.com/3471790

Discount! And as you are a reader of my blog, for at least the next 10 days until the end of July you can go to the link above and get a 25% discount by using this code: 77ULP6VH

 

And on Amazon with free shipping! 

 

 

.

6/23/2011

SharePoint: Edit date and time in one minute increments

 

When working with SharePoint date fields you are offered a Date Picker that let’s you select time to the nearest five minutes.

image

While this works fine for most tasks and meetings, some manufacturing processes need the time set to the minute.

.image

 

I first tried some quick JavaScript tricks to change the dropdown list to include 00 to 59, but it appears that the server side code only expects the dropdown to only have five minute steps and that causes an error on save. The next experiment was to create custom New and Edit forms to allow free form edits. Turns out you don’t have to do anything special to the Display form or the views as they just display whatever was entered.

 

The steps below generally follow what you will find in other blog sites or this MSDN article, expect for replacing the Date Picker fields with Text Box fields.

 

Test this on a “test” list before duplicating on a production list!

 

List Preparation

Before we can enter times, you need to configure your list to support Date and Time. Simply go to the list’s properties and edit the date field to support Date & Time.

image 

Also add a Description to your date fields with a sample of an acceptable date. Remember that the user no longer has a date picker to make sure they select a valid date.  Something like: “Enter dates as mm/dd/yyyy hh:mm AM/PM”

 

Disable Attachments!

      image

The following edits will not work if Attachments are enabled for the list. Go to List Settings, Advanced and disable attachments. I think this error is caused by having two web parts on the same page, each adding some common ID that confuses the page’s JavaScript  (I did a search and found this article, http://support.microsoft.com/kb/953271, but I did not try it’s solution.)

 

Fire Up SharePoint Designer!

SharePoint 2007 (and SPD 2007) example follows – 2010 is farther down the page…

Edit the “New” form  (NewForm.aspx)

SharePoint 2007 steps:

  1. Open SharePoint Designer and open your site   “http://yourserver/sites/.yoursite”
  2. In the Folder List expand Lists and your list
  3. Double-click NewForm.aspx (you may want to make a copy of this file first)
  4. Display the page in Design view
        image
  5. Right-click the existing web part and click Web Part Properties
  6. Expand the Layout section and click Hidden and then click OK
        image
    Note: Do not delete the existing web part!
  7. Click below the existing web part (you may need to experiment to find a spot)
  8. In the menu click Insert, SharePoint Controls and Custom List Form
         image 
  9. Select your list (not just any list with a similar name, your list!)
         image
  10. Select the correct content type
  11. Click New Item Form and click OK
  12. Wait until the fields load
  13. Click on the date field you want to change
  14. If the “Common FormField Tasks” popup is not displayed, right-click the web part and select Show Common Control Tasks
        image
  15. Change the Format As to “Text Box
  16. Repeat for any other date fields you need to change (Start Date and Due Date for a task list)

    Note: In my test environment, SharePoint Designer 2007 occasionally locks up here. You may have to try this more than once.
  17. Save your changes and click Yes if prompted about “customize a page”.
        image
  18. Go to a browser and add a new item to the list
        image 

Note: Several different date formats are acceptable for date entries:
      image

 

Edit the “Edit” form  (EditForm.aspx)

SharePoint 2007 steps:

  1. Follow steps 1 – 11 above except double-click EditForm.aspx and select “Edit Item Form
  2. If the fields are not displayed:
    1. Right-click the new web part
    2. Click Show Common Control Tasks
    3. click the Show With Sample Data checkbox
    4. click Refresh Data View.
    5. image

  3. Continue with step 13 from above…

You were probably expecting something like this:

    image

and got this instead:

    image

Go back to the EditForm.aspx page, switch to Code view and search for this line (my example uses @StartDate):

    <asp:TextBox runat=“server” id=”…” text=”{@StartDate}” …

And then replace @StartDate with

    ddwrt:FormatDateTime(string(@StartDate), 1033, 'G')

The result should look like this

    <asp:TextBox runat=“server” id=”…” text="{ddwrt:FormatDateTime(string(@StartDate), 1033, 'g')}"

Now test and confirm that it now looks like this:

        image

 

 

 

Edit the “New” form  (NewForm.aspx)

SharePoint 2010 steps:

  1. Open SharePoint Designer and open your site   “http://yourserver/sites/.yoursite”
  2. In the Navigation section click Lists and Libraries
  3. Double-click your your list
  4. In the Forms section double-click NewForm.aspx (you may want to make a copy of this file first)
  5. Display the page in Design view
        image
  6. Right-click the existing web part and click Web Part Properties
        image
  7. Expand the Layout section and click Hidden and then click OK
       image
    Note: Do not delete the existing web part!
  8. Click below the existing web part (you may need to experiment to find a spot)
  9. In the Insert ribbon click SharePoint (in the Controls section) and Custom List Form
        image
  10. Select your list (not just any list with a similar name, your list!)
        image
  11. Select the correct content type
  12. Click New Item Form and click OK
  13. Wait until the fields load
  14. Click on the date field you want to change
  15. If the “Common FormField Tasks” popup is not displayed, right-click the web part and select  Show Common Control Tasks
        image
  16. Change the Format As to “Text Box
  17. Repeat for any other date fields you need to change (Start Date and Due Date for a task list)
  18. Save your changes
  19. Go to a browser and add a new item to the list
        image 

Note: Several different date formats are acceptable for date entries:
      image

 

 

Edit the “Edit” form  (EditForm.aspx)

SharePoint 2010 steps:

  1. Follow steps 1 – 13 above except double-click EditForm.aspx and select “Edit Item Form
  2. If the fields are not displayed:
    1. Click the “tab” above the new web part:
        image
    2. Click the Design tab in the Data View Tools section of the ribbon
    3. click the Sample Data checkbox
    4.  

  3. Continue with step 14 from above…

You were probably expecting something like this:

    image

and got this instead:

    image

Go back to the EditForm.aspx page, switch to Code view and search for this line (my example uses @StartDate):

    <asp:TextBox runat=“server” id=”…” text=”{@StartDate}” …

And then replace @StartDate with

    ddwrt:FormatDateTime(string(@StartDate), 1033, 'G')

The result should look like this

    <asp:TextBox runat=“server” id=”…” text="{ddwrt:FormatDateTime(string(@StartDate), 1033, 'g')}"

This edit will display “A.D.” in the Design view, but will display the correct data in the browser.

    image

Now test and confirm that it now looks like this:

        image

 

 

 

 

Hours, Minutes and Seconds?

 

SharePoint will store time to the second. There are no additional changes needed for the NewForm.aspx page, and EditForm.aspx only needs the “g” in the FormatDateTime changed to “G”. The real work will be in also creating a custom DispForm.aspx and custom views.

     text="{ddwrt:FormatDateTime(string(@StartDate), 1033, 'G')}"

 

.

Note to spammers!

Spammers, don't waste your time... all posts are moderated. If your comment includes unrelated links, is advertising, or just pure spam, it will never be seen.