I tried to run some scripts in Powershell yesterday on my new SharePoint server, but was unable to do so and I got this message: "The execution is disabled on this system".
The solution to this problem is very simple. Just write the following command:
Set-ExecutionPolicy Unrestricted
Now you will be able to run your ps1 scripts in Powershell.
Saturday, March 1, 2014
Tuesday, February 11, 2014
Project Server - Are you sure you want to navigate away from this page
When creating or editing project in project Server, it implies that you change lots of field values in Project Detail Pages.
After every change on Project Detail Page, you need to click on Save button in Ribbon for changed to be saved. If you don't do that (and you try to navigate away from that page without saving), you will be prompted with the following message: "Are you sure you want to navigate away from this page?"
This is perfectly normal behavior of Project Server.
The problem starts when this message appears when you haven't made any changes on the Project Detail Page. For example: You have made changes on your Project Detail Page and then click on the Save button. But, when you try to navigate away from that page, you get this message. I was confused because I didn't know did Project Server really saved my changes or not.
This seems to be a bug in Project Server this happens when you have more than one multiline text box fields on the page.
I have found one one solution for this problem.
NOTE: This solution changes default scripts of Project Server. It is not recommended by Microsoft to customize this scripts. Actually, it is not allowed and all changes you make to this scripts can cause unexpected behaviour of Project Server.
Now, after you have been properly warned, this is the solution:
1. Go to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\INC\PWA\LIBRARY
2. Find script called "ProjectServerScripts.debug.js" and make a backup of that script (we are going to change the existing script so it is good to have a backup).
3. Open script "ProjectServerScripts.debug.js" and in it find following code:
handleSaveCommand:function(command, properties, sequenceNumber){ULSBk9:;
eval('PDPButton.SaveData(null);');
return true;
},
4. Add one line (marked red) to that method and save changes:
handleSaveCommand:function(command, properties, sequenceNumber){ULSBk9:;
eval('PDPButton.SaveData(null);');
window.onbeforeunload = function(e){}
return true;
},
After every change on Project Detail Page, you need to click on Save button in Ribbon for changed to be saved. If you don't do that (and you try to navigate away from that page without saving), you will be prompted with the following message: "Are you sure you want to navigate away from this page?"
![]() |
| Prompt window for saving changes in Project Server |
This is perfectly normal behavior of Project Server.
The problem starts when this message appears when you haven't made any changes on the Project Detail Page. For example: You have made changes on your Project Detail Page and then click on the Save button. But, when you try to navigate away from that page, you get this message. I was confused because I didn't know did Project Server really saved my changes or not.
This seems to be a bug in Project Server this happens when you have more than one multiline text box fields on the page.
I have found one one solution for this problem.
NOTE: This solution changes default scripts of Project Server. It is not recommended by Microsoft to customize this scripts. Actually, it is not allowed and all changes you make to this scripts can cause unexpected behaviour of Project Server.
Now, after you have been properly warned, this is the solution:
1. Go to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\INC\PWA\LIBRARY
2. Find script called "ProjectServerScripts.debug.js" and make a backup of that script (we are going to change the existing script so it is good to have a backup).
3. Open script "ProjectServerScripts.debug.js" and in it find following code:
handleSaveCommand:function(command, properties, sequenceNumber){ULSBk9:;
eval('PDPButton.SaveData(null);');
return true;
},
4. Add one line (marked red) to that method and save changes:
handleSaveCommand:function(command, properties, sequenceNumber){ULSBk9:;
eval('PDPButton.SaveData(null);');
window.onbeforeunload = function(e){}
return true;
},
Monday, December 30, 2013
Project Server - check if project is approved
This is my new post in my Project Server series. In this post, I've written short c# code (using PSI) on how to check if project in Project Server is already approved.
This short code comes in handy when you need to do some action only after the project is approved.
Other posts regarding Project Server PSI functions: how to use PSI in Project Server in simple way, how to get values from Custom Fields from code with PSI, how to restart workflow from code using PSI, get members of Project Server group using PSI, change EPT using PSI and how to update Custom Field using PSI.
This is the C# code:
This short code comes in handy when you need to do some action only after the project is approved.
Other posts regarding Project Server PSI functions: how to use PSI in Project Server in simple way, how to get values from Custom Fields from code with PSI, how to restart workflow from code using PSI, get members of Project Server group using PSI, change EPT using PSI and how to update Custom Field using PSI.
This is the C# code:
public static bool IsProjectApproved(Guid
projectUid)
{
var logService = new LogService();
var sessionService = new
PSSessionService()
{
HostName = "serverName", // your PWA host name
SiteName = "pwa" // your PWA site name
};
// we need this user for LoginContext (it can be read from app settings)
string _user = "Username";
string _userPwd = "Pass";
string _userDomain = "Domain";
using (var _loginCtx
= new LoginContext(_userDomain
+ "\\" + _user, _userPwd,
sessionService))
{
try
{
PsiContextService
psiContextService = new PsiContextService();
PSISvcsFactory psiSvcsFactory = new PSISvcsFactory(sessionService,
psiContextService);
Workflow _wfSvc =
psiSvcsFactory.CreateSvcClient<Workflow>();
WorkflowDataSet dtWf = _wfSvc.ReadWorkflowStatus(projectUid, true);
// _max is the last ORDER of the Status in DB
int _max = -1;
bool _status = false;
foreach (var
item in dtWf.WorkflowStatus)
{
if (item.STAGE_ORDER > _max)
{
_max =
item.STAGE_ORDER;
if (item.STAGE_INFO.ToLower().Contains("project approved"))
_status = true;
else
_status = false;
}
}
return _status;
}
catch (Exception)
{
return
false;
}
}
}
Monday, December 23, 2013
Project Server - check if project is checked-out to current user
In my previous posts on Project Server, I wrote on how to use PSI in Project Server in simple way, how to get values from Custom Fields from code with PSI, how to restart workflow from code using PSI, get members of Project Server group using PSI, change EPT using PSI and how to update Custom Field using PSI.
Today, I will show how to check (with PSI) if currently logged-in user is equal to the user to which project is checked-out. This can be useful many times, for example, if something is to be done with the project data from code, but someone else has checked-out the project, and, in that case the current user must not be able to edit project data.
For this small piece of code, I am using FluentPS library, like it is mentioned in post that I linked at the top of this post.
This is the code in c#:
// we need this user for LoginContext (it can be read from app settings)
using (var _loginCtx
= new LoginContext(_userDomain
+ "\\" + _user, _userPwd,
sessionService))
Today, I will show how to check (with PSI) if currently logged-in user is equal to the user to which project is checked-out. This can be useful many times, for example, if something is to be done with the project data from code, but someone else has checked-out the project, and, in that case the current user must not be able to edit project data.
For this small piece of code, I am using FluentPS library, like it is mentioned in post that I linked at the top of this post.
This is the code in c#:
public static bool IsProjectCheckedOutToCurrentUser(Guid projectUid)
{
var logService = new LogService();
var sessionService = new
PSSessionService()
{
HostName = "serverName", // your PWA host name
SiteName = "pwa" // your PWA site name
};
// we need this user for LoginContext (it can be read from app settings)
string _user = "dev";
string _userPwd = "pass";
string _userDomain = "domain";
{
sessionService.SetLoginContext(_loginCtx);
FluentPS.Services.Impl.PsiContextService
psiContextService = new PsiContextService();
FluentPS.Services.Impl.PSISvcsFactory
psiSvcsFactory = new PSISvcsFactory(sessionService,
psiContextService);
FluentPS.WebSvcLookupTable.LookupTable
svcLookupTable = psiSvcsFactory.CreateSvcClient<FluentPS.WebSvcLookupTable.LookupTable>();
FluentPS.WebSvcCustomFields.CustomFields
svcCustomFields =
psiSvcsFactory.CreateSvcClient<FluentPS.WebSvcCustomFields.CustomFields>();
FluentPS.WebSvcProject.Project
svcProject = psiSvcsFactory.CreateSvcClient<FluentPS.WebSvcProject.Project>();
FluentPS.WebSvcResource.Resource
svcResource = psiSvcsFactory.CreateSvcClient<FluentPS.WebSvcResource.Resource>();
FluentPS.WebSvcProject.ProjectDataSet _projEntities = svcProject.ReadProjectEntities(projectUid, 32,
FluentPS.WebSvcProject.DataStoreEnum.WorkingStore);
FluentPS.WebSvcProject.ProjectDataSet _project = svcProject.ReadProject(projectUid, FluentPS.WebSvcProject.DataStoreEnum.WorkingStore);
try
{
Guid _checkOutUser = Guid.Empty;
Guid _currentUser = Guid.Empty;
using (var
dsProject = svcProject.ReadProject(projectUid, DataStoreEnum.WorkingStore))
{
var projectRow = dsProject.Project.FindByPROJ_UID(projectUid);
if (projectRow == null)
return false;
if(!projectRow.IsPROJ_CHECKOUTBYNull())
_checkOutUser =
projectRow.PROJ_CHECKOUTBY;
}
using (FluentPS.WebSvcResource.ResourceDataSet resourceDs =
svcResource.ReadUserList(FluentPS.WebSvcResource.ResourceActiveFilter.All))
{
foreach (var item in resourceDs.Resources)
{
if (item.WRES_ACCOUNT.Contains(HttpContext.Current.User.Identity.Name))
{
_currentUser =
item.RES_UID;
}
}
}
if (_checkOutUser == Guid.Empty || _currentUser == Guid.Empty)
return false;
if (_checkOutUser == _currentUser)
return true;
else
return false;
}
catch (Exception
ex)
{
return
false;
}
}
}
What is the GAC folder
When developing solutions for SharePoint platform, you will often deploy your solutions to GAC folder and use libraries that are already deployed to GAC, maybe even without knowing it.
What is GAC folder?
Global Assembly Cache (or simply, GAC) is a special folder in Windows designed for storing .NET global DLLs. When you deploy your SharePoint solution, you are actually deploying that DLL to GAC folder.
Location of GAC is C:\Windows\assembly or, in newer versions of .NET Framework (4.0): C:\Windows\Microsoft.NET\assembly.
When your try to access those paths, you can see that this isn't the ordinary folder, you can't simply copy/paste files to that folder or delete files from it. Of course, there is a way of opening GAC as ordinary folder, but it is not recommended for you to do it because you can accidentally erase DLL that some other application is using.
But, if you want to open GAC as "ordinary" folder, do the following steps:
1. Go to Start --> Run
2. Write c:\windows\assembly\gac_msil
And now you can add or delete files form GAC as in any other folder.
Better way of registering/removing solutions to/from GAC, is with use of command prompt, i.e. command line utility gacutil.exe.
If you want to register an assembly in GAC, use command:
When we are talking about SharePoint Farm solutions, every solution is automatically registered in GAC as soon as you hit "Deploy" in Visual Studio or if you are deploying from command prompt.
If you want to deploy another library along with your SharePoint solution, the only thing you need is to add that library to the package in your SharePoint solution.
1. Open the package in Solution Explorer in Visual Studio
2. The package opens in Design view. Click on Advanced tab on the bottom of the package screen.
3. And now, you can add the desired DLL to that package and every time you deploy that SharePoint solution, newly added DLL will also be deployed to GAC.
What is GAC folder?
Global Assembly Cache (or simply, GAC) is a special folder in Windows designed for storing .NET global DLLs. When you deploy your SharePoint solution, you are actually deploying that DLL to GAC folder.
Location of GAC is C:\Windows\assembly or, in newer versions of .NET Framework (4.0): C:\Windows\Microsoft.NET\assembly.
When your try to access those paths, you can see that this isn't the ordinary folder, you can't simply copy/paste files to that folder or delete files from it. Of course, there is a way of opening GAC as ordinary folder, but it is not recommended for you to do it because you can accidentally erase DLL that some other application is using.
But, if you want to open GAC as "ordinary" folder, do the following steps:
1. Go to Start --> Run
2. Write c:\windows\assembly\gac_msil
And now you can add or delete files form GAC as in any other folder.
Better way of registering/removing solutions to/from GAC, is with use of command prompt, i.e. command line utility gacutil.exe.
If you want to register an assembly in GAC, use command:
gacutil.exe /i <entirePath\assemblyName>
If you want to remove an assembly from GAC, use command:
gacutil.exe /u <assemblyName>
When we are talking about SharePoint Farm solutions, every solution is automatically registered in GAC as soon as you hit "Deploy" in Visual Studio or if you are deploying from command prompt.
If you want to deploy another library along with your SharePoint solution, the only thing you need is to add that library to the package in your SharePoint solution.
1. Open the package in Solution Explorer in Visual Studio
2. The package opens in Design view. Click on Advanced tab on the bottom of the package screen.
3. And now, you can add the desired DLL to that package and every time you deploy that SharePoint solution, newly added DLL will also be deployed to GAC.
Subscribe to:
Posts (Atom)


