Thursday, 30 August 2012

Formatting a FormView data bound string


Instead of:
<asp:Label ID="Label_Age" runat="server" 
Text='<%# Eval("CalculatedAgeMonths") %>' />

Use:
<asp:Label ID="Label_Age" runat="server" 
Text='<%#  ConvertToYearsMonths(Eval("CalculatedAgeMonths")) %>' />


And in your code behind:
Function ConvertToYearsMonths(CurrentMonths As Integer) As String

     Return "in Years!!"

End Function

Microsoft IIS Versions


MS IIS: Microsoft Internet Information Server

XP       = IIS 5.1
Server 2003 = IIS 6
Server 2008 = IIS 7
Windows 7   = IIS 7.5

Microsoft Egypt announces the Windows Server 2012 online global launch! :(


Will that mean that there will be no day off to enjoy the event at a splendid site?!

Virtual Launch events are nice; however, they for sure exclude may opportunities for physical interactions. Getting together semi-formally with x-colleagues in the industry, getting an opportunity to meet the masters of the technology, whom you, might already, are virtually dealing with them on frequent basis in the day-to-day operations.

What about the guys presenting their efforts? They deserve feeling appreciated from the community and looked at with proud from their peers and sub-ordinates.

Algorithms: Banana problem

From an old story about a girl who can pronounce banana; however, she just doesn't know when to stop!

This can be used to describe algorithms with termination problems.

ALV

The term:
A: Application
L: List 
V: Viewer
 A term specially used for reports analyzers.


The product ;)
Apache Log Viewer
http://www.apacheviewer.com/function.php
This is a nice free log analyzer

Wednesday, 29 August 2012

No! Don't accept responsibility without authority

That's actually, one of the highest risk decisions:

Taking a responsibility to deliver a project which involves resources  whom\which you have no official control upon. At time, you can consider yourself working on good will basis! Good luck!

Sunday, 26 August 2012

Difference between SharePoint "View Only" & Read permissions

View Only: Can view all site objects within the application; however, unable to open content within client side applications.
Quote:
"If the document has a server-side file handler available, they can only view the document using the server-side file handler."
UnQuote


Read: View Only + open content within client side applications, such as word documents from Ms Office Word application on the client.



Saturday, 25 August 2012

Installing unsupported HP Laserjet 1010 within Windows 7 x32 or x64

For HP, you have to go to the trade-in program:
http://www.hp.com/united-states/tradein/home_flash.html


Within the community, of course that is not the perfect choice:

Thanks goes for the post by Michael Westphal:

http://h30499.www3.hp.com/t5/Printers-LaserJet/LaserJet-1010-Windows-7-X64-Drivers/td-p/1124953

Steps are:

1) "Install new printer" in Windows control center.
2) "Local printer"
3) "DOT4_001 (Generic IEEE....)"


4) "HP Jaserjet 3055 PCL5"


Done!

Tuesday, 21 August 2012

Calculate Age using TSQL

This is a modified version from the original post by Michael Valentine Jones Yak DBA Kernel 


CREATE function [dbo].[fn_Age](@START_DATE datetime, @END_DATE datetime)
returns  varchar(9) 
as
-- Original version @http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=62729
-- Calculates age in years, months and days from @START_DATE through @END_DATE and
-- Returns the age in format YYY MM DD.

-- Years is the number of full years between @START_DATE and @END_DATE.
-- Months is the number of full months since the last full year anniversary.
-- Days is the number of days since the last full month anniversary.
BEGIN
--([dbo].[fn_Age](isnull([DOB],getdate()),getdate()))

declare @AGE varchar(9)

declare @AGE_YEARS int
declare @AGE_MONTHS int
declare @AGE_DAYS int

-- Return null if @START_DATE > @END_DATE
IF @START_DATE > @END_DATE BEGIN RETURN @AGE END

SELECT @AGE_YEARS = AGE_YEARS,
@AGE_MONTHS = AGE_MONTHS,
@AGE_DAYS = datediff(dd, dateadd(mm, AGE_MONTHS, dateadd(yy, AGE_YEARS, START_DATE)),END_DATE)
FROM (SELECT AGE_MONTHS = CASE WHEN AnniversaryThisMonth <= END_DATE
THEN datediff(mm,dateadd(yy,AGE_YEARS,START_DATE),END_DATE)
ELSE datediff(mm,dateadd(yy,AGE_YEARS,START_DATE),END_DATE)-1
END, *
FROM (SELECT AGE_YEARS = CASE WHEN AnniversaryThisYear <= END_DATE
THEN datediff(yy,START_DATE,END_DATE)
ELSE datediff(yy,START_DATE,END_DATE)-1
END, *
FROM (SELECT AnniversaryThisYear = dateadd(yy,datediff(yy,START_DATE,END_DATE),START_DATE),
AnniversaryThisMonth = dateadd(mm,datediff(mm,START_DATE,END_DATE),START_DATE), *
FROM (Select START_DATE = dateadd(dd,datediff(dd, 0, @START_DATE),0), END_DATE = dateadd(dd, datediff(dd, 0, @END_DATE),0)) Temp4
) Temp3
) Temp2
) Temp1

SELECT @AGE = right('000'+convert(varchar(4),@AGE_YEARS),3) + ' ' +
right('00'+convert(varchar(4),@AGE_MONTHS),2) + ' ' +
right('00'+convert(varchar(4),@AGE_DAYS),2)

RETURN @AGE
END

SQL Server Computed column drawback

On creating a computed column using a function, you will no longer be able to alter this function, unless you remove it from the computed column expression.

Otherwise you will get the error message:
Cannot ALTER 'dbo.fn_test' because it is being referenced by object 'Tester'

Saturday, 18 August 2012

outlook.com

The really killer feature from my point of view is editing few office documents online!

Outlook.com

The really killer drawback, if not remedied the earliest is the performance. It requires a lot of tweaking; for example, saving to skydrive  requires a significant amount of time!


Another important but acceptable issue with this revolutionary interface is the lack of most features in the office applications, frankly, I only played for some time with Work and PowerPoint. 

Thursday, 16 August 2012

Sending e-mails with attachments using ASP.NET

Public Shared Sub SendEmail
(ByVal recipientToCsv As String, 
ByVal subject As String, 
ByVal body As String,
Optional ByVal isHtml As Boolean = True, 
Optional ByVal recipientCCCsv As String = "", 
Optional ByVal recipientBCCCsv As String = "", 
Optional ByVal Attachment1_Stream As Stream = Nothing, 
Optional ByVal Attachment1_filename As String = "")

'Create the email object
Dim newEmail As New MailMessage()

' From
newEmail.From = New MailAddress(System.Configuration.ConfigurationManager.AppSettings.Item("AppMailboxAddress"), System.Configuration.ConfigurationManager.AppSettings.Item("AppMailboxAddressName"))

' To
If String.IsNullOrEmpty(recipientToCsv) Then
recipientToCsv = System.Configuration.ConfigurationManager.AppSettings.Item("AppMailboxAddress")
End If
newEmail.To.Add(recipientToCsv)

' CC
If Trim(recipientCCCsv) <> "" Then newEmail.CC.Add(recipientCCCsv)
If Trim(System.Configuration.ConfigurationManager.AppSettings.Item("CCMailboxAddress")) <> "" Then newEmail.CC.Add(System.Configuration.ConfigurationManager.AppSettings.Item("CCMailboxAddress"))

' BCC
If Trim(recipientBCCCsv) <> "" Then newEmail.Bcc.Add(recipientBCCCsv)
If Trim(System.Configuration.ConfigurationManager.AppSettings.Item("BCCMailboxAddress")) <> "" Then newEmail.Bcc.Add(System.Configuration.ConfigurationManager.AppSettings.Item("BCCMailboxAddress"))

' Subject
newEmail.Subject = subject

' Body
newEmail.IsBodyHtml = isHtml
newEmail.Body = body

' Attachment
If Not IsNothing(Attachment1_Stream) Then
   Dim Attachment1 As Attachment = New Attachment(Attachment1_Stream, Attachment1_filename)
   newEmail.Attachments.Add(Attachment1)
End If

'Send the email
Dim smtp As New SmtpClient
smtp.Send(newEmail)

End Sub

Disseminating accountability among sub-ordinates

1) Give them the responsibility.
2) Define the task.
3) Speak it out.
4) Guidance and mentoring on request.

5) Transparent evaluation: Specific performance and attitude resulted in judged outcomes
6) Share finals: Success\Failure

7) Patience: The above steps are not once and for all, they are iterative per task!

Wednesday, 15 August 2012

AJAX Control Toolkit Resizable Control handle disappears behinde Control

Increase X and\or Y offsets:


<ajaxToolkit:ResizableControlExtender ID="ReportViewer_Main_ResizableControlExtender" runat="server" Enabled="True" TargetControlID="ReportViewer_Main" HandleCssClass="HandleHand" HandleOffsetX ="16" HandleOffsetY ="0" MaximumHeight="600" MinimumHeight="600">



Note: Microsoft Report Viewer did not scale well when vertically re-sized, therefore I limited the re-size horizontally!

[OLE DB Source_Access [29]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.


That was an SSIS to transfer data from an Access DB 2007 into SQL Server 2012 using SSIS


[OLE DB Source_Access [29]] Error: SSIS Error Code DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER.
The AcquireConnection method call to the connection manager XXX"" failed with error code 0xC0209303.
There may be error messages posted before this with more information on why the AcquireConnection method call failed.


SET RUN 64 to False from the project properties:






Tuesday, 14 August 2012

Unable to open an Access .mdb file

This is not the main cause; however, read this strange scenario, you might be another victim:

When I double clicked an .mdb file to open it on my new machine which have MS Office 2010 installed, including Access, it just opened another Office interface rather than Access without any  access features and in the status bar, it was written, "Powered by Microsoft Access".

When I open the Access application from the Start Menu, it initiated the Setup application and configured itself.

Back to the .mdb, when I clicked it, it opened like a charm!!!

Thursday, 9 August 2012

.htaccess case insensitive redirection

RedirectMatch (?i)\/abc http://applications.mysite.com/NewABC

ASP.NET Error: The MaximumValue 150 cannot be less than the MinimumValue 38 of RangeValidator


Just specify the comparison type

Type="Double"  

Manipulate FormView values in the code behind

Instead of:
<asp:Label ID="Label_Age" runat="server" Text='<%# Eval("CalculatedAgeMonths") %>' />

Use:
<asp:Label ID="Label_Age" runat="server" Text='<%# ConvertToYearsMonths(Eval("CalculatedAgeMonths")) %>' />

And in your code behind:

Function ConvertToYearsMonths(CurrentMonths As Integer) As String
     Return "in Years!!"
End Function

Wednesday, 8 August 2012

Can't edit photos copied from iPhone 4S iOS 5 to Windows 7 in Windows Photo viewer

Unfortunately, me too!!

Workaround, right click the photo and click Edit to open it in "Paint" application where you will be able to rotate and save.

Thursday, 2 August 2012

Sanitizer provider is not configured in the web.config file. If you are using the HtmlEditorExtender with a public website then please configure a Sanitizer provider.


Sanitizer provider is not configured in the web.config file. If you are using the HtmlEditorExtender with a public website then please configure a Sanitizer provider. Otherwise, set the EnableSanitization property to false.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: Sanitizer provider is not configured in the web.config file. If you are using the HtmlEditorExtender with a public website then please configure a Sanitizer provider. Otherwise, set the EnableSanitization property to false.




Place the below section just below the openieng of "<configuration>" tag within the file "web.config"


<configSections>
        <sectionGroup name="system.web">
            <section name="sanitizer" requirePermission="false" type="AjaxControlToolkit.Sanitizer.ProviderSanitizerSection, AjaxControlToolkit"/>
        </sectionGroup>
    </configSections>
    <system.web>
        <sanitizer defaultProvider="AntiXssSanitizerProvider">
            <providers>
                <add name="AntiXssSanitizerProvider" type="AjaxControlToolkit.Sanitizer.AntiXssSanitizerProvider"></add>
            </providers>
        </sanitizer>
    </system.web>


Anti-XSS can be easily obtained using NuGet. (Similar to previous post for installing AjaxControl Toolkit)

Visual Studio 2010 --> Tools --> Library Package Manager --> Package Manager Console -->
PM> Install-Package AntiXSS

You will get the below error if Anti-XSS is not installed:

Could not load type 'AjaxControlToolkit.Sanitizer.AntiXssSanitizerProvider'


Wednesday, 1 August 2012

Easy way to install AjaxControlToolKit for Visual Studio 2010



Now you have new menu item "Library Package Manager" inside "Tools" menu for Visual Studio 2010.
Visual Studio 2010--> Tools --> Library Package Manager


PM> Get-Package -Filter AjaxControlToolkit -ListAvailable
PM> Install-Package AjaxControlToolkit 

If you are behind a proxy, most probably you will be prompt for your account to pass it into downloading the package.

"Downloading..." in Visual Studio Status bar

Successfully installed 'AjaxControlToolkit 4.1.60623'.
Successfully added 'AjaxControlToolkit 4.1.60623' to Source.

References:
http://docs.nuget.org/docs/start-here/using-the-package-manager-console

e.AffectedRows usually returns -1 (SqlDataSource_Inserting)

In your stored procedure, enable the counting:

SET NOCOUNT OFF;


It is ON by Default in the stored procedure template.

SharePoint: Permitting users to edit their list items only

SharePoint List --> Settings --> Advanced Settings: