28 novembre 2007

How to show the CalendarExtender over a dropdown?

1. Add a new item (Style Sheet) to your project and call it ajaxcalendarfix.css
2. In the css file paste the following:
.ajax__calendar
{
position: relative;
left: 0px !important;
top: 0px !important;
visibility: visible;
display: block;
}
.ajax__calendar iframe
{
left: 0px !important;
top: 0px !important;
}

3. In your MasterPage (or aspx page if you're not using a MasterPage) include the following line in your "head" section below all other css entries (change the path for your unique setup):



4. In the CssClass properties of your Calendar Extender, type: ajax__calendar ajaxcalendarfix
Note the space character between "ajax__calendar" and "ajaxcalendarfix".
This will take the default css properties of the Ajax Calendar and apply the bug fix in ajaxcalendarfix. Using this solution, I didn't have to mess with div tags, IFrames, z-indexes, etc.

Team Foundation Server - Undo Check Out

On various projects, there are occassions when files are left locked by team members leaving the project or while on long vacations. In VSS, the administrator could simply select the file(s) and chose to undo-checkout.
A couple of months ago, our TFS installation was moved from one domain to another and some files were locked out with user accounts from a domain that was retired. Well, being the admin, I thought it was just a matter of selecting the files and unlocking them. Well, guess what - the option either didnt show up or when it did, it was grayed out. After researching this, I found out that the way to unlock, undo-check out is using the command line options:1. Check the status of the file in question
c:\tf status "$/ProjectRoot/Project/File" /server: /format:detailed

2. Since we need to know the name of the workspace for the next few commands, the following command will give us this information
c:\tf workspaces /owner:\ /computer:* /server:

3. Unlock the 'locked' file
c:\tf lock /lock:none "$/ProjectRoot/Project/File" /workspace:;\ /s:

4. If required, undo the changes using the following command
c:\tf undo "$/ProjectRoot/Project/File" /workspace:;\ /server:

For each of the above commands, you need to have the correct administrative rights on the project/TFS server.

18 octobre 2007

Response.Redirect into a new Window

It is "not possible" to redirect into a new window, because a redirect on the server causes a special HTTP response to be sent to the users browser, the client. The browsers native implementation interprets the special response code and sends the user off to the destination. The only way to open a new window is for it to be initiated on the client side, whether it be through script or clicking on a link.
So the solution always proposed to this problem is to instead write out some script that opens the window, rather than using Response.Redirect:



public static void Redirect(string url, string target, string windowFeatures)
{
HttpContext context = HttpContext.Current;
if ((String.IsNullOrEmpty(target) target.Equals("_self", StringComparison.OrdinalIgnoreCase)) && String.IsNullOrEmpty(windowFeatures))
{
context.Response.Redirect(url);
}
else
{
System.Web.UI.Page page = (System.Web.UI.Page)context.Handler;
if (page == null)
{
throw new InvalidOperationException("Cannot redirect to new window outside Page context.");
}
url = page.ResolveClientUrl(url);
string script;
if (!String.IsNullOrEmpty(windowFeatures))
{
script = @"window.open(""{0}"", ""{1}"", ""{2}"");";
}
else
{
script = @"window.open(""{0}"", ""{1}"");";
}
script = String.Format(script, url, target, windowFeatures);
ScriptManager.RegisterStartupScript(page, typeof(System.Web.UI.Page), "Redirect", script, true);
}
}



Than, use this method like:

Redirect("MyPage.aspx", "_blank", "status=no,toolbar=no,menubar=no,location=no,resizable=yes,titlebar=no");

17 octobre 2007

Concurrent access in ASP.NET

I want to know how many people are connected on my Web application
A user is in a group and we want to know if there is a user of the group who's inthe Site. But, it's possible to have 2 guys who use the same account. So i found this solution, with the Session and the Application in DotNet 2.0.

int ConnectedCount = 0;
if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
{

//Dynamic string if you have more than 1 group of users
string HashTableName = "NameOfMyHashtable"
if (System.Web.HttpContext.Current.Session != null)
{

//Create new Hashtable if null:
Application[HashTableName] = Application[HashTableName] ?? new Hashtable();

//region Refresh information about current User
if (((Hashtable)Application[HashTableName]).Contains

(System.Web.HttpContext.Current.Session.SessionID))
{
((Hashtable) Application[HashTableName]).Remove

(System.Web.HttpContext.Current.Session.SessionID);
}
((Hashtable) Application[HashTableName]).Add(System.Web.HttpContext.Current.Session.SessionID,
DateTime.Now.AddMinutes(System.Web.HttpContext.Current.Session.Timeout));

//region clean Hashtable
foreach (string pKeys in ((Hashtable) Application[HashTableName]).Keys)
{
if (((DateTime) ((Hashtable) Application[HashTableName])[pKeys]).CompareTo(DateTime.Now) <

connectedcount =" ((Hashtable)"> 0 )
{
lblUsersConnected.Attributes.Add("class", "fontMessageError fade");
lblUsersConnected.Text = "Attention, il y a déjà " + ConnectedCount + " utilisateur connecté";
}

}

Collection was modified; enumeration operation may not execute.

If we want to change a value in a Hashtable, there is a problem with the Foreach loop:
Hashtable MyHt=new Hashtable();
MyHt.Add("my key", "my value");
.....

foreach (DictionaryEntry entry in MyHt)
{
MyHt[entry.Key] = "my value";
}
The is the error message :
"Collection was modified; enumeration operation may not execute."

So for resolve this, we juste do an
ArrayList arrayList = new ArrayList(((Hashtable)Application[AppName]).Keys);
IEnumerator listEnumerator = arrayList.GetEnumerator();
while (listEnumerator.MoveNext())
{
((Hashtable)Application[AppName])[Session.SessionID.ToString()] = DateTime.Now.AddMinutes(10);
Hashtable ht = (Hashtable)Application[AppName];
DateTime dateOfSession = Convert.ToDateTime(ht[listEnumerator.Current].ToString());
if (dateOfSession.CompareTo(DateTime.Now) < 0)
{
((Hashtable)Application[AppName]).Remove(Session.SessionID.ToString());
}
}

27 avril 2007

Use IComparer to Sort a Generic list<>

Best possibility to compare is to use the IComparer interface :


public class SortFileByDate:IComparer
{


#region IComparer Members

public int Compare(Report x, Report y)
{
return DateTime.Compare(y.Date, x.Date);
}

#endregion
}


To use it, for example:


List listOfObjects = new List();

listOfObjects.add(New Report("bla",date);
listOfObjects.Sort(new SortFileByDate());

Failed to access IIS Metabase


If you're like me and have both ASP.NET 1.1 and 2.0 on your machine (along with the associated Visual Studio 2003 and 2005 products because you can't help but write software in both environments) you may encounter this issue. Upon running your website (via http://localhost/xxx or something like that), you may encounter the error page that reports:

Failed to access IIS metabase


If so, you may have installed IIS after installing the .NET framework. If that's the case, try running to repair your ASP.NET installation and set up all of the appropriate ISAPI extension mappings.

aspnet_regiis -i


If, however, you're like me and had IIS already installed, and you installed VS 2003 and then VS 2005, and then set up a 1.1 virtual directory / website, simply check that the appropriate ASP.NET version is associated with it (Select VDIR --> Properties --> ASP.NET tab).

22 mars 2007

Remove accent of a string
éèàçùö =>eeacuo

private string ConvertToRemovedAccentAndLowerCase(string txt)
{
byte[] bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt);
return System.Text.Encoding.ASCII.GetString(bytes);
}

Remove accents

Remove accent of a string
éèàçùö =>eeacuo

private string ConvertToRemovedAccentAndLowerCase(string txt)
{
byte[] bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(txt);
return System.Text.Encoding.ASCII.GetString(bytes);
}

21 mars 2007

FxCopCmd.exe Error code 65



Exit code 65 means that analysis errors occured (exit code 1) and that the report could not be written (64). This probably is happening because the solution folder is not writable. Check if the solution folder for the website (commonly under My Documents\Visual Studio 2005\Solutions) is read only or has security restrictions.

The file generated is for example "CodeAnalysisLog.xml" in a directory like "{123ABCDE21-......}"

14 mars 2007

Sorted files by LastWriteTime

private static List SortFilesByLastWriteTime(string path, string filter)
{
FileInfo[] fi = new DirectoryInfo(path).GetFiles(filter);
List fis = new List();
fis.AddRange(fi);
fis.Sort(new Comparison(
delegate(FileInfo f1, FileInfo f2)
{
return f1.LastWriteTime.CompareTo(f2.LastWriteTime);
}));
return fis;
}