Twitter Feed Popout byInfofru

Modifying Connection Properties of excel file

We need to modify about 100+ excel files which are connecting to data connections files sitting in d

We were in need to modify about 100+ excel files which are connecting to data connections files sitting in data connection library of SharePoint 2010. The property we needed to change is “Always user connection file” in connection properties as shown below. Of course programmatically.

image

First of, I added the reference of “Microsoft.Office.Interop.Excel” in project and include it in code, like below

using xls = Microsoft.Office.Interop.Excel;

Then, read excel file from physical location and changed its connection properties using the code below

var application = new xls.Application();
try
{       

var application = new xls.Application();   // Creating excel application object
try
{
     string readLocation = @"D:\Documents\myfile_1.xlsx";
     var workbook = application.Workbooks.Open(readLocation); // Open excel workbook

    foreach (xls.WorkbookConnection con in workbook.Connections) // Iterating all connections
     {

            // Check for other properties, if you have to. For me, I am dead sure that all files wouldn’t be using connection files
             con.OLEDBConnection.AlwaysUseConnectionFile = true;
     }

    workbook.Save(); // Saving back workbook
}
catch (Exception)
{
     throw;
}
finally
{

        // These clean up lines are important to run otherwise, you will end up having an orphan excel instance sitting idle.
         application.Workbooks.Close();
         application.Quit();
}

Permission denied on IE 11

From yesterday, I was having a weird issue in our legacy SharePoint 2010, where all IE 11 users were reporting problems in new release that had substantial amount of JavaScript modifications. I started to investigate by looking at the console and found Permission denied error. Awesome, a step closer to resolve the issue but haven’t had the grab of any useful information about it. I was having the Permission denied error various times on console like below.

image

I had a look into all these lines of code and I realize that permission denied was occurring each time the “document” object being called and then I notice the following line at the top of the console section.

image

It led me to believe that compatibility setting would resolve this. So in IE, I went to Emulation section of developers tools, change the document mode from 8 (Default) to 10 as can be seen in the snapshot below.

image

Aha! the errors had disappeared and JavaScript started to work fine. Now, in order to force client’s browser to use the document mode 10 by default, following meta tag should be specified in master page.

<meta http-equiv="X-UA-Compatible" content="IE=10"/>

How to redirect to default login page from action

I have been using Authorize attribute heavily to manage user authorizations, but at times just Authorize attribute is not enough. For an instance, I want user to access the Edit page of any entity which he created. In other words I don’t want him to edit records created by other users.

We cannot do this using Authorize only because it is design to limit access to an action regardless of what data is being passed to it. Thus, in this case you can maintain CreatedUser field in the record table and check on the Action if the logged in user is authorize to do this edit. Here is the code for that.

 

if (myrecord.OwnerId != User.Identity.Name) {

return new HttpUnauthorizedResult();

}

 

You can return HttpStatusCodeResult(403) too but that will only display the default access denied page of IIS, which is not we want and this is where “HttpUnauthorizedResult” comes handy.

Statusbar settings in Cordova (IOS)

When I first try to deploy my Cordova application on IOS, the statusbar was blending with app header

When I first try to deploy my Cordova application on IOS, the statusbar was blending with app header. Below is how it was displayed. 

 

From IOS 7 and on statusbar has become the part of the running app to allow developers do something creative with it. It can be useful if you are using it but in routine hybrid apps, we don't need to do that. Luckily, there are two ways to configure statusbar. 

Config.XML: 

There are three configuration element that can be used. Just specify them in your config.xml and you will be all good to go. 

<preference name="StatusBarOverlaysWebview" value="false" />
<preference name="StatusBarBackgroundColor" value="#669F36"/>
<preference name="StatusBarStyle" value="lightcontent" />

For more configurational options, check http://goo.gl/y0cUQI

Programable approach (Using plugin):

By installing a plugin (which is preinstalled in all ionic templates) we can do it programmatically and it will override all StatusBar settings specified in Config.XML. 

angular.module('ionicApp', ['ionic']).run(function ($ionicPlatform, $cordovaSQLite) {

 if (window.StatusBar) {
              
                    StatusBar.overlaysWebView(false);
                 StatusBar.backgroundColorByHexString('#669F36');
                    StatusBar.styleLightContent();
                    
                }

})

Results:

In either approach, below is how you see the statusbar if you set overlaysWebView to false, give it a decent background and a lightcontent style. 


Most Important Note:

Just in case if you don't see any reflection of these configuration in your application, you should remove ios and add it again (sometimes restart do miracles). 

I spent hours to figure it out. In my application, statusBar settings were not working at all. So, I removed and add ios platform again. 

 cordova platform remove ios
 cordova platform add ios

 

Deploy cordova application on specific ios emulator image

Lets make some simple stuff more complicated and more powerful. Below&amp;nbsp;is&amp;nbsp;a cute command to

Lets make some simple stuff more complicated and more powerful. Below is a cute command to emulate your cordova app on ios simulator or device. 

cordova run ios 
//or
cordova emulate ios

First shell command will search for the connected device and if not found just deploy the app to the default emulator and run it. 

Well in my scenario, I want to deploy my app to to iPhone 6 emulator image which uses IOS 8.4. To do that I first wants to know what are the available emulator images I have installed. Below script will do that

./platforms/ios/cordova/lib/list-emulator-images

Following output is from my machine

iPhone-4s, 8.4
iPhone-4s, 9.2
iPhone-5, 8.4
iPhone-5, 9.2
iPhone-5s, 8.4
iPhone-5s, 9.2
iPhone-6, 8.4
iPhone-6, 9.2

Just in case if you don't find emulator image of your choice. You can go to Simulator -> Hardware -> Device -> Manage Devices . 

And then click on the (+) button below and then select add simulator

Once you have devices listed in terminal using the shell given above. Below is how you can now deploy your app on specific IOS image

cordova emulate ios --target="iPhone-6, 8.4"

 

 

Permission issues on Cordova run

This afternoon, while I try to run Cordova run ios terminal shows up with bunch of identical ambigu

This afternoon, while I try to run

 cordova run ios

terminal shows up with bunch of identical ambiguous errors. Some of them are as follows 

rm: could not remove file (code EACCES)
Error: EACCES, permission denied

 

Fixing permission:

It is obvious that there is some thing wrong with the permissions. So I decided to put sudo before the command 

sudo cordova run ios

Ok fair enough, the error is changed. Now it says  

Command failed with exit code 2
You may not have the required environment or OS to run this project

Before going further to solve the issue, lets just make sure that we give full permission on folder to the current user.  To know about your actual user name (just to be on safe side) on mac write 

echo $(logname)

Since you know your username now, lets give your user full permission on this folder. To do so, write 

sudo chown -Rv {angrycoder} ~/Documents/Development/phonegap/appname/

where {angrycoder} should replace by your username followed by the full path of your directory. Unfortunately, that didn't help either and it keep showing the same error. 

Actual Issue (XCode License Agreement): 

Even after the permission fixed the problem still exists. I decided to look at some other clue in terminal and finds out following

simctl was not found

It seems that simulation control is not installed. This is insane, I was using the same machine to build all these projects. When I open Xcode to make sure if every thing is working fine it throws An Accept License Agreement Screen before welcome dialog appears. Yes, you read it right ... Accept license was the main culprit. 

So if you encounter similar issue. Make sure to open your XCode and check if Apple wants you to click somewhere. 

Disable validation on field for specific view

Consider a case when you have single model which is bind to multiple views. For example, UserInforma

Consider a case when you have single model which is bind to multiple views. For example, UserInformation model bind to “Create” and “Edit” view. Now in “Create” view, I want to “Password” field as required but at the same time I want it to be optional on “Edit” view.

It means, In “Edit” view, If user provides “Password” then change it otherwise don’t update the “Password” field.

This is why it is important to create ViewModels, which gives you freedom to have different fields, validations etc for every view.

Now to achieve this goal in the given scenario, we need to make two tweaks.

 

Client Side

To disable client side validation, we need to disable it by force.

@Html.EditorFor(model => model.Password, new { htmlAttributes = new {  @data_val = "false" , @class = "form-control"} })

Notice the @data_val= “false”. It will disable the validation on this field.

 

Server Side (In Action)

When the model is validated on the post action, ModelState.IsValid will always return false because password is not provided. Here we have to provide the current password to the model and Re-validate the model.

var userObj = db.Users_Info.Where(a => a.Id == users_Info.Id).FirstOrDefault();

if (String.IsNullOrEmpty(users_Info.Password))
{
    users_Info.Password = userObj.Password;
}

ModelState.Clear();
TryValidateModel(users_Info);

Let me explain, first we retrieve current information saved in the database which we are using later to assign to current model if password is not provided. The last two lines actually reset the ModelState to return updated result on ModelState.IsValid.

Angry Coding Angry smile Angry smile Angry smile

Error : Value cannot be null.Parameter name : PublicKey

This morning, while I added my existing SharePoint project to a solution it start giving me this Error when I do the build.

Error   8   Value cannot be null.Parameter name: PublicKey   

Graphically

ParameterNullPublicKeyError

Strange, because the last time when I run this project it was working fine. Search on the internet doesn’t prove to be much fruitful. So, I compare this project with the existing project which are working fine and realize that for some reason Visual Studio remove the Sign the Assembly checkbox on the project properties and the Public Key is not available. Like below.

 

unsignesvs

So just check the “Sign the assembly” check box which means that you are signing your assembly with the public key which will now available to Visual Studio to build your SharePoint Project and the error will disappear.

VariationRoot.aspx unavailable after restore

Scenario :

After working on some modules, I have to deploy my site collection to an other machine. For that, I used stsadm.

Once the site collection is restore it keep giving me this

Error File Not Found.

Troubleshoot issues with Microsoft SharePoint Foundation.

Graphically :

spvarerr

Of course, my site collection have variation implemented. I spent an hour on it but didn’t find any thing useful. Then Shehzad Ahmed pointed me to the Language Packs.

So if you are restoring a site collection that have Variation Implemented. You have to install Language Packs before.

But this is not the only thing you should care about. In fact, installing languages pack for me didn’t do the job. So I have to open the log file and check what actually is going wrong.

Then, I realize that the web parts that I was deploying from Visual Studio in my development site is not available on the deployment machine.

That is why, I decided to re-deploy all of my modules to the deployment machine and once I done that. It start working fine.

Why I am posting this is because the error is quit confusing ambiguous.

Solving SharePoint 2010 Setup Errors Manually

If you are installing SharePoint 2010 on a new box you might see the Setup Errors notification from the installer. In my case, I am using Windows Server 2008 R2, but I have seen the similar Error on Windows 7 as well with little less requirements.

sperror

As you can understand all the “-“ bullets are the requirements that needs to be installed or configured on the box.

There are two ways to do this

1) Microsoft SharePoint 2010 Product Preparation tool

In the SharePoint 2010 Splash Form, you can find that with title “Install software prerequisites” or alternatively you can run file “PrerequisiteInstaller” on the same folder as of the setup file. 


2) Manual installation of Prerequisites

Now the question is, why would one select to chose the manual installation when we already have utility provided by Microsoft. The answer is that utility some time fails Smile for me at least, it fails 2 / 3 times.

So, let me explain all of them one by one.

- “A System restart …….”

Hopefully you will not see this because I am installing SharePoint 2010 just after an other installation that is why it is there. So if you see this better to restart your machine.

- “This product requires Windows Identity Foundation”

Download  KB Update from http://www.microsoft.com/download/en/details.aspx?id=17331
Select your operating system carefully. Windows 6.1 is for Windows 7 & 2008.

- “……… Sync Framework Runtime”

Download from http://www.microsoft.com/download/en/details.aspx?id=17616
It downloads a zip file which have five folders container some setup. Now, you don’t need to run all the setups. Execute the setup inside “Microsoft Sync Framework” and you are done with this step.

- “…….. SQL Server 2008 Native Client”

Download it form http://www.microsoft.com/download/en/details.aspx?DisplayLang=en&id=8824
Scroll down to find Microsoft SQL Server 2008 Native Client

- “Windows server features or role services required …. ”

For sure, you will not face this issue in Windows 7 because there is nothing like server featured in Windows 7 but In Windows 2008 (maybe) for security reasons you have configure the features that will be used through Server Manager. To do that

1) Go to Server Manager
2) Select the Features from the tree on the left hand
4) On the right hand you have a page with Feature Summary Panel. Click on Add Features and following window will appear.

spsf

From the list of Features  you have to select the following:

.Net Framework 3.5.1 Features with WCF Activation
Message Queue
Remote Server Administration Tool
Windows Process Activation Service with all sub options.
and feature settings is complete.

5) Select the “Roles” from the tree on the left hand.
5) If you are working on a new box, you will see only Role Summary section in the configuration on the right hand.
7) Click the Add Roles button on the Role Summary panel. The following window will appear

spbub

This window is only informing you about the security concerns. So just click next. The following window have the list of Server Roles available. Microsoft SharePoint 2010 require Application Server and Web Server to be installed. So select them from the window.

spssr

Notice the required sections are highlighted in the underline. Since I have all these requirement already installed that is why the buttons are disabled, but it should be enable for you.

In the Web Server (IIS) section, make sure to select asp.net. However, the default selection is what you needed. Once you finish this, your Roles window should look like this

sprw

Containing sections for Application Server and Web Server.

 

- “Microsoft Filter Pack 2.0 required ……..”

Ok, you will find Filter Pack 1.0 easily on internet, but that is not the requirement. Actually, Filter Pack 2.0 is available with the name of Microsoft Office 2010 Filter Packs which actually make sense because SharePoint 2010 is the part of Office Suit 2010. Anyway, you can get it from http://www.microsoft.com/download/en/details.aspx?id=17062


- “Internet Information Services 7.0 or higher is required …….”

In Windows 2008, If you have successfully completed the Features and Roles configuration, this is already done because in Role Configuration we already installed Web Server (IIS).

For Windows 7, you have to make sure that IIS 7.0 is installed and configure to  run asp.net.

- “IIS 6.0 Management Compatibility…….. ”

For windows 2008, it is completed with Features and Roles Configuration. But to make sure

1) Go to Server Manager
2) Roles
3) From the Web Server (IIS) panel on the right hand (not on the tree), maximize the Role Service and see if you have IIS 6 Management Compatibility there like below

spimc

For Windows 7,

1) Go to Program and Features
2) Select Turn Windows features on or off.
3) Make sure you have IIS Management Compatibility feature checked under Internet Information Services.

spimc7

- “Microsoft .net Framework 3.5.1 required  ……. “

For Windows 2008, if you have completed Features and Roles configuration you are done. For Windows 7, just make sure that you have .net Framework 3.5 SP 1 runtime is installed. Get it from http://www.microsoft.com/download/en/details.aspx?id=22

 

- “Hotfix for Microsoft Windows (KB976462)”

This is Windows 2008 R2 Specific, which can be found at
http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=23806

- “Microsoft Chart Control ……..”

It is straight forward setup download which you can get it from here
http://www.microsoft.com/download/en/details.aspx?id=14422

 

Hopefully once the above steps are taken, the setup errors will be finished. Your comments are welcome if you face any issue which is not listed above and you think that can help someone else.