If you had a list of projects listed on the Visual Studio 2005 Home page's Recent Projects section and wanted to clear any of these items, there is not a way to do it using the IDE.
You will need to go to the registry (Start->Run->regedit) and remove entries from:
HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList
It's a common programming technique to use a dataset as a datasource to a grid control. But, if you have a datarow array that is a result of a maybe a SELECT, how would you bind it to a grid?
This is possible by creating a datatable and looping through the datarow array object to populate the datatable. The code is as below:
DataRow[] drArray;
//sb is a stringbuilder that filters the XML. ex: " ID = 100 "
drArray = dsXML.Tables[0].Select(sb.ToString());
DataTable dtTable = dsXML.Tables[0].Clone();
foreach (DataRow dr in drArray)
{
dtTable.ImportRow(dr);
}
GridView1.DataSource = dtTable;
GridView1.DataBind();
I had a XML file that had details of all the events that were going to be held. I had to display in a Web control, all the events that occured in the future. This task was accomplished using the XPath and XPathNodeIterator object in the System.XML.XPath namespace.
Here's the sample XML file:
184
Content
Title
Event 1 Title
2007-02-22
189
Content
Event 2 Title
2007-02-11
Here's the code that creates a XPathNodeIterator object that has a list of all Event IDs.
private void ShowEvents()
{
XPathDocument xDoc = new XPathDocument(Server.MapPath("Test.xml"));
XPathNavigator xNav = xDoc.CreateNavigator();
string strToday = DateTime.Now.ToString("yyyy-MM-dd");
//The Start Date in the XML is in the yyyy-MM-dd format. The translate function in XPath purges the hyphens and
//and a numerical comparison between dates is made.
//This was done because date comparison is not supported in XPath 1.0
string strXPath = "/Collection/Content/Html/root[translate(StartDate,'-','') > \"" + strToday.Replace("-","") + "\"]/../../ID";
XPathNodeIterator xIter = xNav.Select(strXPath);
this.Label1.Text = strXPath;
while (xIter.MoveNext())
{
//xIter.Current.Name has the name of the entity (In this case, it displays "ID")
//xIter.Current.Value has the value of the "ID"
}
}
By default, .NET does not allow you to overload WebMethods by specifying the same method name and changing the parameter list. Instead, Ansil discusses a way of doing this by specifying the MessageName property of the web method.
http://www.codeproject.com/soap/RefAndOL.asp
The standard data sources that SRS supports are the SQL Server, XML, Oracle and ODBC. However, there is a way to have the report use a ADO.NET dataset as its data source. Here are some articles:
http://prologika.com/CS/blogs/blog/archive/2005/11/20/695.aspx
http://msdn2.microsoft.com/en-us/library/aa902651(SQL.80).aspx
I created a Console app and configured it with a Windows Scheduler to run every few minutes. Whenever the schedular kicked off the app, it opened up a window in the foreground. To configure it to run on the background, you will have to run the task under an account other than the logon account.
To do this:
1. Open the Scheduled Tasks
2. Right click on the task and select Properties
3. In the properties window, type in an account other than the logon account and set the password.
4. Click on OK.
Now when the app runs, it runs in the background.
If you are using Visual Studio .NET and try to debug a console application, by default the console application runs without command line arguments. To supply one or more arguments, follow these steps:
1. In the Solution Explorer, select the project.
2. Select View -> Property Pages. The shortcut key is Shift + F4.
3. In the property page window, select Debugging under Configuration Properties
4. In the textbox labeled Command Line Arguments, enter one or more arguments separated by space. If your arguments have a space, you need to enclose them within double quotes.
5. Click OK.
6. When you debug the project now, the arguments will be passed to the application.
To find the LastModifiedDate for a file, you need a handle to the file. The LastWriteName property would then give you the last modified date. If the file is "touched" in anyway, this property is updated to the current DateTime.
Here's the code for a zip file
FileInfo zipFileInfo = new FileInfo(zipFileName);
DateTime dtLastMod = new DateTime();
dtLastMod = zipFileInfo.LastWriteTime; //get the last modified date of the ZIP file
strLastMod = dtLastMod.ToShortDateString();
WriteLog("Last Modified Date is " + strLastMod);
If you are debugging a webservice remotely, you will encounter the "Page cannot be displayed" or the generic error - "HTTP 500 - Internal Server Error" whenever the service throws an exception. If you want to know what error has occurred, you would need to turn off the friendly HTTP error messages in IE.
1. Select "Tools" from the menu in IE
2. Choose "Internet Options"
3. Click on the "Advanced" tab
4. Look down the list for 'Show friendly HTTP error messages' and uncheck the tick box for it followed by the 'Apply' button at the bottom of the dialog box.
Refresh the page that is displaying the HTTP 500 message to see what the error is.
I was "select"ing from a datasource that stored data in the format "Lastname, Firstname" ex: "Smith, John". The fastest way to do this is to tokenize the string with the "," delimiter. However, I realized there is no "split" function in SQL Server.
In SQL Server 2000, a workaround would be to use the SUBSTRING() along with the CHARINDEX().
SELECT SUBSTRING(Name, 0, CHARINDEX(',', Name)) AS LastName, SUBSTRING(Name, CHARINDEX(',', Name) + 1, LEN(Name)) AS FirstNameFROM Customers
SQL-DMO (SQL Server Distributed Management Objects) lets you programmatically get a list of SQL Servers in the network.
1. Ensure you have the latest SQL Server Service Pack. You could find out which version you are using by doing a SELECT @@VERSION
2. In your C# app, add a reference to sqldmo.dll (You need to select the COM tab when adding a reference)
3. Add the namespace
using SQLDMO;
4. The code that discovers the SQL Servers is:
SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
SQLDMO.NameList sqlServers = sqlApp.ListAvailableSQLServers();
//Note that in COM, index starts from 1
long lCount = sqlServers.Count;
for (int i=1; i <= lCount; i++)
{
string str = sqlServers.Item(i);
Console.WriteLine(str);
}
5. Execute the application and you would see a list of SQL Servers. You could connect to a SQL Server by creating an instance of SQLServerClass as below:
SQLDMO.SQLServer mysqlserver = new SQLDMO.SQLServerClass();
mysqlserver.Connect("name of the server","sa","password");
Console.WriteLine("Connected...");
I was attempting to restore a SQL database from a .bak file when QA complained about incorrect Logical Name. Resolving it was a 2 step process:
1. Get the Physical Name and the Logical Name by:
RESTORE FILELISTONLY FROM DISK='C:\DB.BAK'
Note down the LogicalName for both the MDF and the LDF file and restore the DB using:
2. RESTORE DATABASE DAM FROM DISK='C:\DB.BAK' WITH MOVE 'DB_DATA_Data' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\DB_DATA_Data.mdf', MOVE 'DB_DATA_Log' to 'C:\Program Files\Microsoft SQL Server\MSSQL\Data\DB_DATA_Log.ldf'
I was trying to implement something similar to what you would see when you login to your bank account online. After the session times out, the user is redirected to the Login page. Here's what i used to get it to work.
In your pages, you would make the body a server control and assign an ID.
Testing.aspx
<body runat="server" id="body">
<form id="Form1" method="post" runat="server">
</form>
</body>
In the code behind of the page, you would declare the “body” as a HtmlGenericControl and add a OnLoad Attribute
Testing.aspx.vb
Protected WithEvents body As System.Web.UI.HtmlControls.HtmlGenericControl
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
body.Attributes.Add("onLoad", "window.setTimeout(""window.location.href='login.aspx'""," & (Session.Timeout * 60 * 1000) + 5000 & ");")
Response.Write("Wait for session to timeout..")
End Sub
If you have a eventhandler handling more than one control, how would you know which of the controls invoked the handler?
Protected
Sub PaymentChecked(ByVal sender As Object, ByVal e As EventArgs) Handles rbfull.CheckedChanged, rbpartial.CheckedChanged
Dim rbClicked As New RadioButton
rbClicked =
CType(sender, RadioButton)
If rbClicked.ID = "rbpartial" Then
'Called by rbpartial radiobutton
ElseIf rbClicked.ID = "rbfull" Then
'Called by rbfull radiobutton
End if
Okay, I passed the 70-229 exam and am a step closer to getting my MCAD. I had earlier passed the 70-315 and I need to take one more test before I get my first MS certification. My prep for 229 included the Que and the MS book. Learnt quite a few new things about SQL Server that I thought never existed. It took me about 2 months of preparation for this one.
However, the question remains. Is the certification really worth all the time and efforts?
I spent the last few days researching on how to create a multisheet workbook. Here are some of the ways that you could do this:
1. Using XML/HTML : http://www.15seconds.com/issue/031007.htm
2. Using OWC : http://www.4guysfromrolla.com/webtech/022801-1.shtml
I ended up using the crude way of creating XML on the fly and doing a Response.Write. Why? The client was not willing to give us the necessary permissions on the server and had no Office XP installed.
While working on one of the projects, I had written this huge stored procedure that took about fifteen seconds to execute it and send the results back to my web page. During this time, I wanted to change the mouse cursor to a hour glass and change it back to a pointer after the procedure is executed.
This is the code I used to change the cursor to a hourglass:
Dim strScript As String
strScript = "<SCRIPT LANGUAGE=javascript>" & vbCrLf
strScript = strScript & "document.body.style.cursor = ""wait"";" & vbCrLf
strScript = strScript & "//-->" & vbCrLf
strScript = strScript & "</SCRIPT>" & vbCrLf
If (Not Me.IsClientScriptBlockRegistered("ChangeCursorType")) Then
Me.RegisterStartupScript("ChangeCursorType", strScript)
End If
To set a default value to a ASP.NET textbox control that has the TextMode = Password property set, insert this code in the code behind file:
PasswordText.Attributes.Add("value", "myPassword")
This is my first blog entry. I am excited about blogging and hope to post some of the new stuff that I learn in .NET daily.