Saed Al Shaar Dev Tips and Tricks

.NET and SharePoint from a different angle!

Remote Access PC through VPN issue

Hi Folks,

Lately I’ve been trying to access my PC at work through the company’s VPN, but with no luck, I though I would share this with you guys.

I noted the PC name and IP address, but when I reach home and try to connect, it gives me an error that the PC name or IP address does not exists.

I thought the problem was from the Remote Access group on the PC, but my account is in the Admin group.

Finally, I was checking my PC Power Options, and found out that the PC will go into Sleep mode after 30min if not used, and that was the problem; everyday when I leave office, it goes into the sleep mode and that was the reason why I couldn’t access it remotely.

To solve this issue, I changed the Power Options so my PC will never go to sleep, and remote access is back again!

Cheers!

 

FREE SharePoint 2013 Training Videos

FREE SharePoint 2013 Training Videos

How-to training and walkthrough videos with this interactive course about
SharePoint 2013 including changes and new features for search, social, plus
deployment and performance/scalability.

Open PDF files within Browser in SharePoint 2010

Hi Folks,

When you open a PDF file in SharePoint 2010, it tends to ask for saving the file on the local drive. Follow the following steps to make it open the PDF files within the browser.

1- Open SharePoint Central Administration.

2- Click on Web Application Management.

3- Highlight the Web Application you want (usually the main site collection on port 80).

4- Click on General Settings.

5- In the Browser File Handling section, choose Permissive.

That’s it!

Happy SharePointing!

Saed

Show PDF Icon in SharePoint 2010

Hi Folks,

This is a brief steps to get the PDF Icon file show on the document libraries in SharePoint 2010:

NOTE: You need to do the following on ALL the Farm servers.

1- Download the PDF icon file (http://www.adobe.com/images/pdficon_small.gif)

2- Copy the GIF file into the following directory in ALL the farm servers.

%Root%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\IMAGES

3- Open the DOCICON.XML file(s) in ALL the farm servers, in the following location:

%Root%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\XML

4- Add the Mapping tag as follows, and then save the files.

<ByExtension> 

          ……..

<Mapping Key=”pdf” Value=”pdficon_small.gif”/>

……..

</ByExtension>

5- Do an IIS reset.

And that’s it!!

Happy SharePointing!

Saed

InfoPath 2007 – MultiView Web based Forms based on Simple Roles

Hi Folks,
Lately, I have been searching for a solution for one of my InfoPath forms where I need to have different view for the person who fills the form at the first time, and another for the Admin of the form.

The issue is that InfoPath 2007 and 2010 does not support a wizard based functionality to check the current user and it’s groups and comparing them with the SharePoint or AD groups, and User Roles is not supported in InfoPath Form Services.

I have checked many good articles talking about using WSS Web Services to retrieve the User Groups and many other complicated stuff, but I don’t like to comlicate things up.

Well, I have thought in a different direction, where I can create my own simple roles as I will explain here:

1- I have an InfoPath Form published on SharePoint document library, with 2 views, the default and Hidden views.

2- I created a sharepoint List named Admin with one column named UserName, and added the user name accounts for the administrators.

3- You need to create a Data connection to the list, if you don’t know how here is a link to do so:
http://office.microsoft.com/en-us/infopath-help/add-a-data-connection-to-a-sharepoint-document-library-or-list-HP010093160.aspx#BM3
You just need to read the part of “Add a query data connection”, at the end you will have a data connection to the Admin list.

4- In the InfoPath form, go to ToolsForm Options — choose Open and Save from Category pane.

5- Click on Rules button, and the Add button to add new rule.

6- Click on Set Condition button on Rule diagram.

7- Then from the drop down menu chose “Select a field or group“.

8- Then Select a Field or Group dialog window will open, chose the Data source for the Admin List, then chose the column name (UserName), and from the Select dropdown chose “Any occurrences of UserName“, then Click OK button.

9- Then, chose “is equal to” , and chose “Use a formula“, a chose the formula “userName()“.

10- Then click on OK button, and now we need to add an action to swith the view named “Hidden” as per the following illustration.

That’s it!

Now, whenever a user from the Admin list open the Form, it will switch to the view named Hidden.

Happy InfoPath-ing!
Saed

Date and Time manipulation

Hi Folks,

Recently I was working with dates and times inside my application, and it took a long time since I figured out how to deal with dates and time.

The senario is that I have an applciation where I store DateTime values in a SQL column, and I created a Form to filter the records based on From Date and To Date.

Here is the Table structure:

And here is sample of the data inside the table:

As you can see that it consists of 2 parts, Date and Time.
Then I created the following form to filter the date column between to dates:
And to filter the dates you can use the following code:
If FromDateTextBox.Text <> “” And ToDateTextBox.Text <> “” Then
           Dim fd As DateTime = DateTime.Parse(LTrim(RTrim(FromDateTextBox.Text)))
           Dim td As DateTime = DateTime.Parse(LTrim(RTrim(ToDateTextBox.Text)))
           criteria += ” AND (Convert(varchar(20), CreatedOn, 101) BETWEEN ‘” & fd & “” & ” And” & td & “)”
End If
The explination:
Convert(varchar(20), CreatedOn, 101 will take the Date only part from the CreatedBy column amdf then we can compare it.
Another note that you need to put the variables values between singlr brackets ‘value’.
Happy programming!
Saed

Zoom It! Tool in action!

Hi Folks,

This time I will not be talking about programming though it’s a very usefull tool for everybody, I will be talking about using Zoom It! tool.

Where you can Zoom In to the screen while presenting your software code, interface or even in any of your presentations and fun stuff.

To download the tool, you just login to Microsoft Windows Sysinternals and search for Zoom It!, here is a link to download.

How to use it:
1- You need to run the Zoom It program.
2- To Zoom in: press Ctrl + 1
3- To Draw on the screen: while in the zome mode, click on the screen, then you can Draw on the screen.
4- To Type on the screen: while in the zoom mode, press the letter “T”, then move the mouse over and start typing.

Below is a sample video I have recorded to show you Zoom It in action.

Happy presentations!
Saed

Validate Current Time in InfoPath

Hi Folks,

Recently I as looking for a way to calculate the current time in InfoPath to be used in the default value field or the validation, I’ve been googling alot but I couldn’t find a solution untill I got it working!

The senario I will be explaining here is I need a field to enter a time, and I want to validate that the time entered should be at least after 1 hour of the current time.

The concept is to get the current time, then add 3600 (60 sec X 60 min) second to it, so the time entered by the user should be Less Than the current time added 3600 seconds (1hour).

The steps goes:
1- In InfoPath, add a Text Box.
2- Open the Text Box Properties window.
3- Change the Data Type to “Time”.
4- Click on the Format button to chage the Time Format to “9:46 AM”.

5- Click OK once, then click on Data Validation button.
6- Then click on Add button in Data validation screen.
7- Choose (is less than), and choose (Use a formula) from the drop down box, to create the formula.
8- Then Insert Formula dialog box will appear.
9- Then click on Insert Function button, the Insert function dialog box will appear.
10- Chose Date and Time, and chose “addSeconds” Function, and click OK button.
11- Then you need to change the formaula as follows:
12- The Formual is: addSeconds(substring-after(now(), “T”), 3600)
This formual will take the time part of NOW() function, then it will add 1 hour (60 sec X 60 min), so the validation will be:
If the field entered is Less Than the Current time + 1 hour, then it will pop up an error, the time should be at least after 1 hour of the current time.
13- Click on OK button, then type the Screen Tip, Message and check the Show dialog box messages …
14- Click on OK button 3 times.
15- Preview the form, and try to type a time after 30 min after your PC current time, it will give you the error as follows:
That’s it!
Happy programming!
Saed

Report Viewer Parameters in Visual Studio 2010 – No Code

Hi Folks,

I’ve been trying since a long time finding an article of how to pass parameters to a Report Viewer control in Visual Studio 2010, but most of the articles needs lots of code to be written.

But, now I have found the way to create a report and pass parameters easily with only 1 line of code, yes I am serious 1 line of code!! :)

And below I will describe the steps with screen shots:
1- You need to create a new Visual Studio Web Site:

2- Then you will have an empty web site.

3- Now, I will create a new database with one table with three columns (ID, Name, City):

Then fill it with some data:

Now I will create a data set for the Contacts table:

Now I will Rebuild the web site:

Now, we need to add reference to Microsoft.ReportViewer.WebForms:
Make sure to select Version 10.0.0.0

Now, I will create a report:


Save the report.

Now, I will start to build the page of the report:
- Add a DropdownList and a Button:

- Drop a Script Manager control into the page:

- Drop a ReportViewer control:

- Choose the Report we created before, and an ObjectDataSource will be created directly:

- On the Click event of the button write the only Code you need to write to refresh the report:
ReportViewer1.LocalReport.Refresh()

Congratulations!! the web site is ready and the report takes the parameter and refreshes.

Happy programming!
Saed

Trick: Roles in ASP.NET and Windows Authentication

Hi Folks,

I have been reading about how to enable Roles in a Windows Authentication in an ASP.NET Web Application, and then I came throught this trick which I wanted to share with you, here it goes:

One tip/trick I like to use is to take advantage of the “Application_Start” event handler within Global.asax to setup my Roles if they don’t already exist, and map any initial users into them if necessary. To-do this, choose File – Add New Item and select the “Global.asax” file item. Then add this code to your Application_Start event handler:

Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
If (Roles.RoleExists(“Auditors”) = False) Then
    Roles.CreateRole(“Auditors”)
End If
If (Roles.RoleExists(“Approvers”) = False) Then
    Roles.CreateRole(“Approvers”)
End If
If (Roles.RoleExists(“Admins”) = False) Then
    Roles.CreateRole(“Admins”)
    Roles.AddUserToRole(“YOURCOMPANY\yourusername”, “Admins”)
End If
End Sub

Or, you can check the Scott’s full post in the following link:
Recipe: Implementing Role-Based Security with ASP.NET 2.0 using Windows Authentication and SQL Server

Happy programming!
Saed

Post Navigation

Follow

Get every new post delivered to your Inbox.

Join 26 other followers

%d bloggers like this: