Wednesday, April 7, 2010

Get date for specified day of month in asp.net

'This code can be used when you want to find any specific date based on day of month
'like first monday of month,second tues day of month etc.


'declare first day of month
Dim M As String = "9"
Dim Y As String = "2011"
Dim fdm As DateTime = Convert.ToDateTime(M & "/01/" & Y)
'if suppose you have to find second friday of a month then use
fdm = fdm.AddDays(7) 'so that you will get a date of second week
'then loop to find the day specified as shown below
While Not fdm.DayOfWeek.ToString().ToLower().Contains("friday")
fdm = fdm.AddDays(1) 'move forward one day untill u get the specified Day
End While

lblDate.Text = fdm.ToString()

'similarly add 11 days for 3rd day, 21 days for 4th day.
'for first day do not add any day

Friday, March 19, 2010

Add thin horizontal line in a row of table

< tr >< td style="border-top:solid 1px #a0a0a0" >< / td >< / tr >

Thursday, March 18, 2010

< a > tag in ItemTemplate

target="_blank" will open the link in new window.

< a target = " _blank " hre f= ' < % # "Page.aspx?QueryString="+ Cstr(Eval("QValue"))% > ' > < % # Eval("ValueToShow")% >< /a >

Friday, March 12, 2010

Format date and money value in asp.net source page

<%# CDate(Eval("Date")).ToString("dd/MM/yyyy") %>

<%# CDbl(Eval("Money")).ToString("0.00") %>

Format("{0:0.00}",Fields.FieldName)

Thursday, March 11, 2010

IIF In Aspx Page

<%# IIf(Convert.ToString(Eval("Field")).Length > 0, "Yes", Eval("Field"))%>

Thursday, March 4, 2010

The additional offender groans.

The additional offender groans.

Friday, February 19, 2010

Find GridView Row And DataKey Value

Dim row As GridViewRow = DirectCast((DirectCast(e.CommandSource, LinkButton).NamingContainer), GridViewRow)
Dim RollNo As Integer
RollNo = CInt(MyGridView.DataKeys(row.RowIndex).Value)

Monday, February 15, 2010

Download File From FTP

Response.Buffer = true;
Response.Clear();


Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);

Response.Flush();
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(FullFilePath));

reqFTP.Proxy = null;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential("userid", "password");



WebResponse aa = reqFTP.GetResponse();
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
MemoryStream MemStream = new MemoryStream();
int bufferSize = 2048;
byte[] respBuffer = new byte[bufferSize];
try
{
int bytesRead = ftpStream.Read(respBuffer, 0, respBuffer.Length);

while (bytesRead > 0)
{
MemStream.Write(respBuffer, 0, bytesRead);
bytesRead = ftpStream.Read(respBuffer, 0, respBuffer.Length);

}
byte[] finalByte = MemStream.GetBuffer();
Response.BinaryWrite(finalByte);