Monday, December 19, 2011

.net get the first and last day of week

Sample code :



Dim dt As DateTime = DateTime.Now
Dim wkStDt As DateTime = DateTime.MinValue
Dim wkEndDt As DateTime = DateTime.MinValue
wkStDt = dt.AddDays(1 - Convert.ToDouble(dt.DayOfWeek))
wkEndDt = dt.AddDays(7 - Convert.ToDouble(dt.DayOfWeek))
Response.Write(wkStDt.ToString("MMMM-dd") & "<br/>")
Response.Write(wkEndDt.ToString("MMMM-dd"))


keyword : first day of week, last day of week, vb.net, .net

Microsoft.XMLHTTP responseText return question mark

Microsoft.XMLHTTP responseText return question mark

responseText actually doesnt support for non ascii character... the alternative is you can get the binary ( responseBody ) and covert to string. Example like below.


function bin2str(vt_array)
      dim idx, tmpStr
      for idx = 1 To LenB(vt_array)
            tmpStr = tmpStr & Chr(AscB(MidB(vt_array, idx, 1)))
      next
      bin2str = tmpStr
end function

Dim objH, str
' Create an xmlhttp object:
Set objH = Server.CreateObject("Microsoft.XMLHTTP")
objH.Open "GET", "http://www.test.com/test.asp", False
     
' Send the request and return the data:
objH.Send
str = bin2str(objH.responseBody)
response.write Server.HTMLEncode(str)


keyword: asp,  Microsoft.XMLHTTP, responseText, question mark, responseBody