Tuesday, April 17, 2012

SSRS - Link to Open Outlook and compose email

SSRS - Link to Open Outlook and compose email

SQL Reporting Services is a very powerful tool to build Reports. 

In one of my projects, my client wanted to have a link in the report so that when user click on the link it open outlook and compose an email with a pre-define emails and subject so that user can compose the email and don't worry about recipients or subject line. This is how it can be implemented:

  • Add a Text box control to your report
  • right click on text box  and go to properties
  • Go to "Action" tab within properties
  • Click on "Go to URL" option
  • click on Fx" Button to the right side of URL drop down (see picture below)
  • put this line there
 ="MailTo:" & "[EmailAddress]" & "?subject" & "[Subject Line]"

  ([EmailAddress] and [Subject Line] should be replace by email and subject that you like the email composed with 


Wednesday, September 7, 2011

How to disable a button (e.g. Submit button) on client side

If you want to disable a button as soon as user click on it (so they don't click multiple times) , you have to do it on client side. Below is how you can do this.


  1. Add the button first



<asp:button causesvalidation="false" id="SubmitButton" onclick="SubmitButton_Click" onclientclick="DisableSubmitButton()" runat="server" text="Submit" usesubmitbehavior="false">


  1. Add this JavaScript function to the page and you set to go.


function DisableSubmitButton(url) {
var button = document.getElementById('&lt;%= SubmitButton.ClientID %&gt;');
button.disabled = true
button.value = 'Submitting...';
__doPostBack('SubmitRadButton', '')
}

How to post code snippet on blogger

I had hard time to put my code snippet on blogger and that is because I don't do that much of blogging but I am starting to enjoy it. Thanks to BlogPandit  to give the instructions for this. I am just repeating them.

When you want to add part of your code (specially asp.net code) you need to do couple of steps to get the code ready for blogger editor. Here they are:


  1. Get your code parsed using the following link Blogcrowds 
  2. Get the parsed code and put it inside of  blockquote tags 
  3. Your are good to go



Tuesday, April 12, 2011

Print Multipe documents in Word in silent mode

Problem:
printing multiple word documents (e.g. 2000 word document) within a folder takes a long time as MS-Word try to open each document, print it. One my clients have this issue which took about 7 hours to print 2000 word documents.

Solution
After a research (thanks to google for bringing the right result in searches most of the time) I find this Forum that someone wrote the script (to be used in MS-Word or Excel) to solve the problem

http://forums.techguy.org/business-applications/485943-printing-multiple-files-folder.html

Thanks to user "Rolling_Again" that wrote the code and share it.  I put the code below as the original didn't work for me. I got error in Application.Filesearch so I find a way to do the same functionality without it. Below is the code,

To run it All you need to do is :
  • open MS-Word or Excel
  • Open "Macro"  section  (under "View" in office 2007)
  • Copy the code on vb script screen that opened  and save it
  • Run "Print All" module, It will open folder selector to let you chose which folder and then it will print all documents with extension "*.doc" within that folder
'API Declares

Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpbi As BrowseInfo) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal hMem As Long)

'API Constants
Private Const MAX_PATH = 260
Private Const BIF_RETURNONLYFSDIRS = 1
Private Const BIF_STATUSTEXT = 4
Private Const WM_USER = &H400
Private Const BFFM_INITIALIZED = 1
Private Const BFFM_SELCHANGED = 2
Private Const BFFM_SETSTATUSTEXTA = (WM_USER + 100)
Private Const BFFM_SETSELECTIONA = (WM_USER + 102)



'BrowseInfo Type
Private Type BrowseInfo
hwndOwner As Long
pIDLRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type


'Private Variables

Private m_sDefaultFolder As String
Public Sub BrowseFolder()
frmBrowse.Show
frmBrowse.txtDirectory.Text = ""
End Sub


Public Function BrowseForFolder(DefaultFolder As String, Optional Parent As Long = 0, Optional Caption As String = "") As String
Dim bi As BrowseInfo
Dim sResult As String, nResult As Long
bi.hwndOwner = Parent
bi.pIDLRoot = 0
bi.pszDisplayName = String$(MAX_PATH, Chr$(0))
If Len(Caption) > 0 Then
bi.lpszTitle = Caption
End If

bi.ulFlags = BIF_RETURNONLYFSDIRS
bi.lpfn = GetAddress(AddressOf BrowseCallbackProc)
bi.lParam = 0
bi.iImage = 0
m_sDefaultFolder = DefaultFolder
nResult = SHBrowseForFolder(bi)

If nResult &lt;> 0 Then
sResult = String(MAX_PATH, 0)

If SHGetPathFromIDList(nResult, sResult) Then
BrowseForFolder = Left$(sResult, InStr(sResult, Chr$(0)) - 1)
End If

CoTaskMemFree nResult
End If

End Function


Private Function BrowseCallbackProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal lParam As Long, ByVal lpData As Long) As Long
Select Case uMsg
Case BFFM_INITIALIZED
If Len(m_sDefaultFolder) > 0 Then
SendMessage hwnd, BFFM_SETSELECTIONA, True, ByVal m_sDefaultFolder
End If
End Select
End Function

Private Function GetAddress(nAddress As Long) As Long
GetAddress = nAddress
End Function

Public Sub PrintAll()

Dim txtDirectory As String
txtDirectory = BrowseForFolder(txtDirectory, , "&Select a directory:")
ChDir txtDirectory
sFile = Dir("*.doc")
Do While sFile &lt;> ""
Application.PrintOut , , , , , , , , , , , , CStr(txtDirectory & "\" & sFile)
sFile = Dir
Loop
End Sub

Sub AccessDeliveryPopUpMenu()
'
' AccessDeliveryPopUpMenu Macro
'
'
End Sub

Sunday, June 13, 2010

Problem With UpdatePanel and FormView

I got to this problem the other day which I thought is good to share it.

Situation 
In one of my ASP.NET application, I have a "Form View" which is bind to a database. For some reason, I needed to use Update Panel (Ajax) to implement click event without server post back. So I used it and it works fine but the problem was when I submit my Form View to save information, the controls that are inside of "Update Panel" would not updated on SQL database even though the update method called. 


Solution 
After a little bit of research, I found out that is bug with Update Panel and Form View but there is a work around. to fix it. All you need to do is to use "Updating" event of Form View and set the value of controls that are inside of "Update Panel" by using e.InputParameter[0] (Take a look at sample below. notice that we cast e.InputParameter[0] as the object of entity/class that bound to form view   and that solve the issue. here is some sample code :




        protected void odsMatterDetail_Updating(object sender, ObjectDataSourceMethodEventArgs e)
        {
       
            //update items that are inside Update panel AJax. because of Update Panel items not bound back to form
            YesNoControl YesNoControlHST = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlHST");
            YesNoControl YesNoControlIsCanadian = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlIsCanadian");
            YesNoControl YesNoControlIsCndLitigation = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlIsCndLitigation");
            YesNoControl YesNoControlHasLitigationCommence = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlHasLitigationCommence");
            YesNoControl YesNoControlHasRealPropertyInCnd = (YesNoControl)MatterDetailFormview.FindControl("YesNoControlHasRealPropertyInCnd");




            LookupListBoxControl LookupListBoxOfficeProvince = (LookupListBoxControl)MatterDetailFormview.FindControl("LookupListBoxOfficeProvince");
            LookupListBoxControl LookupListBoxLitigationProvince = 
                                                              (LookupListBoxControl)MatterDetailFormview.FindControl("LookupListBoxLitigationProvince");
            LookupListBoxControl LookupListBoxRealPropProvince = 
                                                              (LookupListBoxControl)MatterDetailFormview.FindControl("LookupListBoxRealPropProvince");




            (e.InputParameters[0] as MatterDetail).IsGSTApplied = YesNoControlHST.Value;
            (e.InputParameters[0] as MatterDetail).IsCanadianClient = YesNoControlIsCanadian.Value;
            (e.InputParameters[0] as MatterDetail).ClientOfficeProvinceCode = LookupListBoxOfficeProvince.Value;
            
            (e.InputParameters[0] as MatterDetail).IsCanadianLitigationMatter = YesNoControlIsCndLitigation.Value;
            (e.InputParameters[0] as MatterDetail).HasLitigationCommenced = YesNoControlHasLitigationCommence.Value;
            (e.InputParameters[0] as MatterDetail).LitigationProvinceCode = LookupListBoxLitigationProvince.Value;




            (e.InputParameters[0] as MatterDetail).HasRealPropertyInCanada = YesNoControlHasRealPropertyInCnd.Value;
            (e.InputParameters[0] as MatterDetail).RealPropertyProvinceCode = LookupListBoxRealPropProvince.Value;




            (e.InputParameters[0] as MatterDetail).ModifBy = Security.CurrentUserID;
        }



Happy Coding 
:-0)

Tuesday, April 20, 2010

Issue with VSEWSS 1.3 when having interface in multiple assemblies

I got this post completely from John W Powell blog. I spent a lot of time to fix the issue I had with VSEWSS 1.3 and the solution was in his post. Thanks to John,



Visual Studio Extensions for Windows SharePoint Services (VSEWSS) Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information

One error you may see when packaging solutions with VSEWSS is:  Microsoft.SharePoint.Tools.Utilities.VSeWSSServiceException VSeWSS Service Error: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.  Like most error messages from VSEWSS, there is not enough information provided to resolve the issue, so I hope to save you some time by providing a workaround that will permanently fix this problem.
When VSEWSS packages your solution, it uses reflection to enumerate the packaged assemblies.  It works fine until it encounters an assembly that implements an interface that is defined in another assembly as is often the case in the Microsoft.Practices.* assemblies.  I am unsure of exactly why, but the extensions are unable to resolve the dependent assemblies.  To work around the issue, you can copy the dependent assemblies to the GAC, but I don’t think this is the optimal solution and doing so will cause pain during development and debugging.  Another option is to copy the dependent assemblies to the VSEWSS service bin directory post build.  After trying this for awhile, and maintaining the script, I decided it would be much simpler to just copy all assemblies in my solution to the VSEWSS service bin directory on post build.  Here is the script:
@rem======================================================================
@rem
@rem    This script copies assemblies to the VSEWSS bin directory
@rem    to eliminate the packaging type load exception that occurs
@rem    when an interface is defined in a separate assembly.
@rem    
@rem    usage call $(ProjectDir)Scripts/CopyAssembliesToVSEWSSBin.bat $(TargetDir)
@rem
@rem======================================================================

@echo off

@echo ========== Locating VSEWSS bin directory ==========
@set vsewssbin=%programfiles%\Microsoft SharePoint Developer Tools 9.0\svc\bin
if not exist "%vsewssbin%" set vsewssbin=%ProgramW6432%\Microsoft SharePoint Developer Tools 9.0\svc\bin
@echo VSEWSS bin: %vsewssbin%

@echo ========== Copying assemblies to VSEWSS bin directory ==========
@xcopy "%1*.dll" "%vsewssbin%" /R /Y

To use the script, create a bat file in your project and call it from a post build event. It does take 64-bit installations into account, and it will also work on your Team Build server.

here is the link to original post

Issue with VSEWSS 1.3 when having interface in multiple assemblies

Happy Coding :)

Wednesday, January 13, 2010

The resource cannot be found.

Today I spent almost 4 hours to figure out why when I change my master page on my sharepoint site, I will get this error:

--------------------------------------------------------------

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /en/Pages/Home.aspx


Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082

--------------------------------------------------------------------------------------

At first I thought the web part or resource files for languages are not deployed., Try to remove them and still couldn't find any clue. As I mentioned in one of my blogs, I turned off the friendly error messages hoping I got more detail about error but all I got was the above error :(

Thanks to MARC CHARMOIS for his article which finally gave me clue how to find missing resource. All you need to do is to go to "view source" of the page and look for "FileNotFoundException" and you will see what is missing :)

you can see Marc's full article here "Resolve Error : The resource cannot be found"

Happy Coding :-)