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.