Azhar’s Web Blog

November 10, 2009

Crystal Reports – Dynamic Images

Filed under: Uncategorized — ajavaid @ 14:01

In Ultrabot Product, we show Ultrabot logo on the top right corner of the page header. This image is embedded into the crystal report file. Some time when a product instance is customized for a client, client asks to replace the Ultrabot logo with some other image. Changing the logo for a customized instance was a manual and time consuming process. We had to open each crystal report file and replace the logo image.

Now, we have used a crystal report property to load the image dynamically. Image path is stored into setup_constants.asp file and is loaded on the reports. So now if we want to change the logo on all reports, we will just need to change the constant in the setup_constants.asp file. This technique will help us to change the logo quickly and to have different logos for different instances by just changing the path in the setup_constants.asp file.

With the addition of this functionality, please note the following steps for each new report that is designed for Ultrabot Product and other versions:

· Add a new Parameter Field: pMainReportLogo

· Copy the Logo from one of the existing reports and place it in the appropriate position on the report

· Edit the Format Formula

o “Right Click logo à Format Graphic… à Picture (Tab 2) à Change Location”

o Enter {?pMainReportLogo} in the above mentioned format formula

Please note that, without performing the above mentioned steps the report cannot be displayed properly.

If you have any further questions, please let me know. Thanks.

Retain Searh/Filter Values in ASP

Filed under: ASP — ajavaid @ 13:59

Hi All,

I have recently added a long awaited feature in ultrabot to retain the search filters on the list pages. E.g. Previously, if you search for a specific user set and edit one of the user, on coming back to the main users list the search criteria was lost and users had to re-search.

This problem is fixed now and Ultrabot retains the search filters in the above mentioned (and other similar) cases. Search filters for a list are cleared on either pressing the clear and search buttons or navigating away from the list form by clicking on the links in the main menu.
The usage of this functionality is quite straight forward, but we need to take care of this while adding/modifying any field on the search section of the list forms.

For now, all main lists support this functionality and it can be further added to any list. If you want to see from code, if the list supports search cache or not, just search for the variable “mainListName” in the source code. if this variable is defined then all future items in the search area must be compatible with this technique. Please follow the following instructions:

mainKeywords = Request.Form(“txtKeywords”)

Replace this with

mainKeywords = GetSearchField(mainListName,

Where

Search fields for the drop-downs can be used as:

mainCategoryID = CLng(GetSearchField(mainListName, “Category”, “cbCategory”, “-1″))

April 25, 2009

A Generic way to Get IDs of server controls in java-script

Filed under: C#, HTML, Javascript — Tags: , , — ajavaid @ 18:08


While working with ASP.Net and java-script, we need to manipulate the HTML objects on the form. If these objects are coded as server side controls, the ids on the client side are different to what we have on the server side.

E.g. a server side text box added in a page with ID=textTitle will have its client id=ctl00_ContentPlaceHolder1_textTitle. (ctl00 is sequence identifier, ContentPlaceHolder1 is id of the parent container and txtTitle is the actual object id) The value of the client id depends on the location of the control, if we add the same control in a different position or we move it inside a user control, its client id will be different.

So one option is to hard-code its client id to access the object in java-script. But this option does not seem appropriate, as the client id can be different with time, with either addition of the new controls or with moving the object to a user control or a similar reason.

Following approach solves this problem to some extent; this approach automates the process of mapping the server and client ids of all objects on a page.

  1. Include the jsClientHtmlObjects.js into the page.
  2. Add the code mentioned in the BasePage.cs to your page class (or its base class)
  3. Include the following script to the end of the page.aspx file just before the </body> tag:

    <
    script type=”text/javascript” language=”javascript”>
             <%=ClientObjectsList%>
    </script>
  4. In Javascript, where you want to access the client instance of the server side object, call the mthods:
    • objClientHtmlObjects.GetObject(serverID) //To get the HTML object with the passed server id
    • objClientHtmlObjects.GetValue(serverID) //To get the HTML object’s value with the passed server id

February 26, 2009

Add CSS to a page dynamically

Filed under: CSS, HTML, Javascript — Tags: , , — ajavaid @ 11:45

 Sometime, we need to add some CSS to a page dynamically.

We can use the following javascript to  add a CSS to a page. This is helful when we are adding/modifying a page in some portal applications like Joomla or Share-point. where we cannot add the CSS to a page in design time.

 

function AddCSS(skinPath)
{
        if(document.createStyleSheet)
       {
            document.createStyleSheet(skinPath);
       }
       else
       
{
              var styles = “@import url(‘ “+skinPath+” ‘);”;
              var newSS=document.createElement(‘link’);
              newSS.rel=’stylesheet’;
              newSS.href=‘data:text/css,’+escape(styles);
              document.getElementsByTagName(“head”)[0].appendChild(newSS);
       }
}

February 21, 2009

Session Expires when Directory.Delete() is called

Filed under: Uncategorized — ajavaid @ 08:00

In DotNet 2.0 and later if we delete some directory inside the web application root, application gets reset and all sessions are expired.

There are different options to resolve this issue, one of the solution is to disable the monitoring on web root:

using System.Reflection;

PropertyInfo p = typeof(System.Web.HttpRuntime).GetProperty(“FileChangesMonitor”, BindingFlags.NonPublic | BindingFlags.Public |  BindingFlags.Static);
object o = p.GetValue(null, null);
FieldInfo f = o.GetType().GetField(“_dirMonSubdirs”, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
object monitor = f.GetValue(o);
MethodInfo m = monitor.GetType().GetMethod(“StopMonitoring”, BindingFlags.Instance | BindingFlags.NonPublic);
m.Invoke(monitor, new object[] { });

February 9, 2009

C# Coding Standard

Filed under: C#, Conventions, Standards — Tags: , , , — ajavaid @ 14:33


While searching for some document on coding standards, i found following links useful:

http://se.ethz.ch/teaching/ss2007/251-0290-00/project/CSharpCodingStandards.pdf

www.dotnetspider.com/tutorials/CodingStandards.doc

Share-point search

Filed under: Administration, Sharepoint, WSS 3.0 — Tags: , , , — ajavaid @ 14:15

A client reported that the search feature is not working on a WSS 3.0 share-point portal. All search queries returned the same following text:

No results matching your search were found.

  1. Check your spelling. Are the words in your query spelled correctly?
  2. Try using synonyms. Maybe what you’re looking for uses slightly different words.
  3. Make your search more general. Try more general terms in place of specific ones.
  4. Try your search in a different scope. Different scopes can have different results.

And an error and a warning kept comming on the server every 5 minutes (after every 5 minutes share-point search service tries to index the share-point sites)

We google the error description but the results did not help – then we google the warning text and were able to find the cause of this problem. Here is the warning that kept on coming every 5 minutes

Event Type:   Warning
Event Source: Windows SharePoint Services 3 Search
Event Category:       Gatherer
Event ID:       2436
Date:            12/26/2007
Time:            3:08:16 AM
User:            N/A
Computer:     AZHAR

Description:
The start address <sts3://dws571210/contentdbid={8a1d4489-b9bd-4ee6-8d24-d8305c6b64f4}> cannot be crawled. 

Context: Application ‘Search index file on the search server’, Catalog ‘Search’

 Details:
          The object was not found.   (0×80041201) 

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Following post helped us in finding the cause of this:

WSSv3 Search, Small Business Server & DNS

As per described in the article, when we tried accessing the site from with-in the server, we were not able to access it. As we were not able to access the site using I.E. the crawler was also not able to access the site and hence it was not indexed. The error The object was not found.   (0×80041201) indicates that the site is not found by the crawler.

As a solution to this problem, we mapped a sub-domain http://site1.myserver.com to the existing URL and we verified that the new URL is accessible from with-in the server. Once this is done the site search feature is back up and running

WSS 2.0 Migration

Filed under: Administration, Sharepoint, WSS 2.0 — Tags: , , , — ajavaid @ 13:05

There are different techniques to migrate WSS 2.0 sites from one server to another. We tried different techniques but most of the techniques had one problem or the other.

After searching on internet and reading supporting documents, we tried the Backup/Restore mechanism using the Share-point administration tool “STSADM.EXE”.

STSADM.EXE is provided with Share-point installations and can be found at the path “… Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\BIN”.

This back-up and restore method moved all the customizations of the portal, all data, users and cross site groups and sub-sites were migrated successfully. Following are some special considerations:

  • If there is any custom web part installed on the source server, make sure to install these on the target server.
  • Once the custom web-parts are configured and the security settings are updated, web-parts will start working.

 

Backup Procedure

Parameter

Required?

Description

-filename

YES

Backup filename. For example, backup.dat.

-url

YES

Web site URL. For example, http://server_name/site.

-overwrite

NO

Overwrite any existing backup file or Web site. By default, the backup operation does not overwrite files. If you do not specify this parameter and a backup file or Web site exists, the operation will stop.

 

 The filename parameter can take any of the following types of information:

 

 

  • A filename, such as backup.dat
  • A path on the local hard disk, such as c:\backups\backup.dat
  • A path on a network share, such as \\share\folder\backup.dat

  Note   Before you run the backup operation, you may want to list all of your sites and identify which sites to back up. To see a list of sites on your server, you can use the enumsites operation. Listing the sites with enumsites can be useful when you are automating backups. You can include enumsites in your batch file, parse the list of sites, and then walk through the list of sites to create the backups. The enumsites operation uses the following syntax:

stsadm.exe -o enumsites -url <url>

Restore Procedure

To restore a site, you use the restore operation with the Stsadm.exe command-line tool. The restore operation takes the same parameters as the backup operation: filename, url, and overwrite.

You have three options for restoring sites from a backup.

4.1 You can restore a site over an existing site

Use this option with caution. When you overwrite an existing site, the existing site is completely overwritten. You cannot merge sites. Any existing site content, and existing site permissions, are destroyed when you overwrite a site.

 

4.2 You can restore a site to a new site on the same server

This is the recommended option. When you restore a site to a new site on the same server, you can copy the data from the restored site, and paste it back into the original site. Use this method if you are restoring a site to recover data.

Note   In order for the restore operation to work correctly, the included and excluded paths for your virtual server must be configured properly. If you are restoring a site to a new site, be sure to create an included path for the site, if necessary, before restoring the site.

4.3 You can restore a site to a separate server

This option can be applied with a separate installation of Windows Share-Point Services that uses a copy of the original server’s configuration database.

This is a more complicated scenario, but it gives you the ability to set up two versions of the same site, as in the previous option, but with the ability to use the unused Web site deletion feature to remove the site automatically after a specific time period. For more information about automatically deleting unused Web sites, see Managing Unused Web Sites.

 Note  If you are trying to recover a particular list or list item from a site backup, use this method to restore the site, and then copy the list or item from the restored site back to the original site.

To restore a site from a backup file, either to a new site or a separate server, you would use syntax similar to the following:

stsadm.exe -o restore -url http://server_name/site -filename backup.dat

To restore a site from a backup file on a server share, and to overwrite any existing site at the new location, you would use syntax similar to the following:

stsadm.exe -o restore -url http://server_name/site -filename \\share\folder\backup.dat

Important Considerations

While we tried the above mentioned process on local server, the backup was not restored and an error was thrown by the restore command that the WSS version is different on local server.
Following is the exact error text:

Error: Your backup is from a different version of Windows SharePoint Services and cannot be restored to a server running the current version

Both the servers had same version of WSS but the live server had Service Pack 1 installed on it, we had to install the same server pack on local server to make the minor version equal to one on live server.

We downloaded following files from the internet and installed these on the local server, which fixed the restore problem:
1. WSS2003-KB924881-FullFile-ENU.exe
2. WSS2003SP1-kb841876-fullfile-enu.exe

References

http://support.microsoft.com/kb/825536
http://office.microsoft.com/en-us/winsharepointadmin/HA011608261033.aspx
http://office.microsoft.com/en-us/sharepointdesigner/HA100699391033.aspx
http://office.microsoft.com/en-us/sharepointdesigner/HA101741391033.aspx
http://blog.crowe.co.nz/archive/2007/09/04/Unable-to-restore-backup-from-WSS-2003-SP2-to-another.aspx

Javascript: Close Main Window

Filed under: Javascript — Tags: , , , — ajavaid @ 10:29

When we call window.close(), it closes the popup windows, that are opened up using the window.open(…) method, without any issue. But when we try to call the method window.open on a main window, that was not opened up using the window.open(…) method, window is not closed  by default and a confirm box is shown first.

In the method window.close(…) javascript simply checks if the window.opener is Null or not, if it is Null a confirm box is shown. So the trick is to set some value in the window.opener variable, this way javascript will treat this window as a popup window and the window.close will work without any message. You can try the following code yourself to experience this:

 /*This function closes the passed (or the current) window without showing the confirm box even if the window is not opened using the window.open method */

function
closeMainWindow(win)
{
          if (!win) //If no windows is passed - close the current window
          {
                    win = window;
          }

          win.opener=‘X’;
          //This will not show the confirm dialog before closing the window.
          //Javascript will treat this window as a Popup.  

          win.open(”, ‘_parent’, ); 
          //Only for IE-7, this line is not needed for IE6
          win.close(); 
          //Now the call to window.close() will not display any warning/confirm dialog on IE6 and IE7
}

Blog at WordPress.com.