|
<html>
<head>
<script language="javascript" type="text/javascript">
function check()
{
var strRegularExpression = document.getElementById("expression").value;
var strVal = document.getElementById("value").value;
if (window.RegExp)
{
var regex = new RegExp(strRegularExpression);
if(regex.test(strVal))
{
document.getElementById("value").style.backgroundColor='#B7F5B5';
alert("Value matches the Expresion");
}
else
{
document.getElementById("value").style.backgroundColor='#FE8080';
alert("Value does not match the Expression");
}
}
}
</script>
</head>
<body style="font-family: verdana">
<table style="height: 58%; width: 100%;" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td style="font-size: 10pt">
Expression: </td>
<td style="font-size: 10pt">
<input type="input" id="expression" style="width: 600px" /></td>
</tr>
<tr>
<td colspan="2" height="5px">
</td>
</tr>
<tr>
<td style="font-size: 10pt">
Value: </td>
<td style="font-size: 10pt">
<input type="input" id="value" style="width: 600px" /></td>
</tr>
<tr>
<td colspan="2" height="5px">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" id="btnEval" title="Check" value="Check" onclick="check()" />
</td>
</tr>
</table>
<td>
</td></td></tr>
</table>
</body>
</html>
<div class="ForumSig">Cheers
Bino
<b>www.codepal.co.in</b></div>
|
|
|
|
|
|
<script type="text/javascript">
var PopWindow = window.createPopup();
function dPopWindow(x,y)
{
var PopupHTML = PopWindow.document.body;
PopupHTML.innerHTML = "<table border=1 style='border-collapse:collapse;'><tr><td><a href='http://www.google.com'>Click Here</a></td></tr></table>";
PopWindow.show(x, y, 100, 25, document.body);
}
document.oncontextmenu = function() { dPopWindow(event.x,event.y);return false; }
</script>
Cheers
Bino
www.codepal.co.nr
|
|
|
|
|
This is kind of workaround or this is the only way to handle this.The scenario is we have a datetime column in which few are NULL.We need to display '-' for this NULL values. There is a catch in this case, we need to split each part of a datetime like date,time and ampm and check each part is null or not.
SELECT column1,Isnull(
(convert(varchar(20),column2,101) + ' ' + convert(varchar(20),column2,108) + ' ' + right(convert(varchar(20),column2),2)),'-') ResuttDate from Table1
Cheers
Bino
www.codepal.co.nr
|
|
|
|
|
string strReturnPathWord = path;
FileStream MyWordFileStream = new FileStream(strReturnPathWord, FileMode.Open);
long FileWordSize;
FileWordSize = MyWordFileStream.Length;
byte[] BufferWord = new byte[FileWordSize];
MyWordFileStream.Read(BufferWord, 0, (int)FileWordSize);
MyWordFileStream.Close();
Response.AddHeader("content-disposition", "attachment;filename=Promissory.rtf");
Response.ContentType = "application/rtf";
Response.BinaryWrite(BufferWord);
Response.End();
Regards
Sean
http://www.codepal.co.nr
|
|
|
|
|
Create a word document with few texts named Name,Company and «DateTime».
The temptext is been replaced using an index based on this text.The second parameter of the substring is calculated as follows
length of the text + 4 + the prefix and suffix characters if any.
ie
len("Name") + 4 = 8 or len("Company") + 4 = 11 or len("«DateTime»")+ 4 + 4 = 16
Here Im using two doc files source and destination in two given folders.Modify as per the requirement.
The C# code is as follows:-
string sourceText;
string tempText;
StreamReader str = new StreamReader( Server.MapPath(@"Source\wordTemplate.rtf"));
str.BaseStream.Seek(0, SeekOrigin.Begin);
sourceText = str.ReadToEnd();
int index = sourceText.IndexOf("Name");
tempText = sourceText.Substring(index-4, 8);
sourceText = sourceText.Replace(tempText, "Sean Archer");
index = sourceText.IndexOf("Company");
tempText= sourceText.Substring(index-4 , 11);
sourceText = sourceText.Replace(tempText, "Microsoft Corp");
index = sourceText.IndexOf("DateTime");
tempText= sourceText.Substring(index-4 , 16);
sourceText = sourceText.Replace(tempText, DateTime.Now.ToString());
str.Close();
StreamWriter stw = new StreamWriter(Server.MapPath(@"Destination\Output.rtf"));
stw.Write(sourceText);
stw.Close();
System.Diagnostics.Process openProcess = new System.Diagnostics.Process();
openProcess.StartInfo.FileName = Server.MapPath(@"Destination\Output.rtf");
openProcess.Start();
Regards
Sean
http://www.codepal.co.nr
|
|
|
|
|
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
public partial class SQLBinary : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//UploadImage();
}
public void UploadImage()
{
// Creating a bytearray[] from the input image
int ImgLen = FileUpload1.PostedFile.ContentLength;
string strSQL="";
byte[] FileImg = new byte[ImgLen];
FileUpload1.PostedFile.InputStream.Read(FileImg, 0, ImgLen);
// Inserting the image to DB
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connstr"].ToString());
try
{
con.Open();
strSQL = "INSERT INTO TESTIMAGE (EIMAGE) VALUES (@pic)";
SqlCommand cmd = new SqlCommand(strSQL, con);
cmd.Parameters.AddWithValue("@pic", FileImg);
cmd.ExecuteNonQuery();
}
finally
{
con.Close();
}
}
protected void btnSave_Click(object sender, EventArgs e)
{
UploadImage();
}
protected void Button1_Click(object sender, EventArgs e)
{
MemoryStream stream = new MemoryStream();
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["connstr"].ToString());
try
{
con.Open();
SqlCommand command = new SqlCommand("SELECT EIMAGE FROM TESTIMAGE", con);
byte[] image = (byte[])command.ExecuteScalar();
stream.Write(image, 0, image.Length);
Bitmap bitmap = new Bitmap(stream);
//To SERVE
//Response.ContentType = "image/gif";
//bitmap.Save(Response.OutputStream, ImageFormat.Gif);
//TO SAVE
bitmap.Save(Server.MapPath("image")+ "/" + "aa.jpg");
Image1.ImageUrl = Server.MapPath("image")+ "/" + "aa.jpg";
}
finally
{
con.Close();
stream.Close();
}
}
}
Regards
Bino
http://www.codepal.co.nr
|
|
|
|
|
function ChkChecked(txtbox,chk)
{
if(chk.checked)
{
txtbox.value = ConcatStr(txtbox.value,chk.value)
}
else
{
txtbox.value = ChkCheckboxes(txtbox.value,chk.value)
}
}
function ConcatStr(XVal,NewVal)
{
XVal += ',' + NewVal
if(XVal.substr(0,1) == ',')
{
XVal = XVal.substr(1,XVal.length)
}
return XVal;
}
function ChkCheckboxes(txtvals,ChkVal)
{
var tmpary = new Array();
var iLoop;
var Result;
tmpary = txtvals.split(",")
Result = '';
for(iLoop=0;iLoop<tmpary.length;iLoop++)
{
if(tmpary[iLoop]!=ChkVal)
{
Result = ConcatStr(Result,tmpary[iLoop])
}
}
return Result;
alert(Result);
}
function SetAllCheckBoxes(FormName, FieldName)
{
if(!document.forms[FormName])
return;
var objCheckBoxes = document.forms[FormName].elements[FieldName];
if(!objCheckBoxes)
return;
var countCheckBoxes = objCheckBoxes.length;
//alert(countCheckBoxes);
if(!countCheckBoxes)
objCheckBoxes.checked = CheckValue;
else
// set the check value for all check boxes
var txtbox = document.getElementById("hdn");
if(document.forms[FormName].elements['all'].checked)
{
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = true;
}
else
{
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = false;
}
if(txtbox.value="")
{
for(var i = 0; i < countCheckBoxes; i++)
{
ChkChecked(txtbox,objCheckBoxes[i]);
}
}
else
{
txtbox.value="";
for(var i = 0; i < countCheckBoxes; i++)
{
ChkChecked(txtbox,objCheckBoxes[i]);
}
}
}
Regards
Bino
|
|
|
|
|
The following section explains in brief how to edit a grid during runtime
Step 1
edit columns
add boundfield
provide the DATAFIELD(the same column name from DB)
click convert into templatefield
add commandfield(edit,update,cancel)
select event rowediting
add the following code
grdTest.EditIndex = e.NewEditIndex;//grdTest is name of the grid
BindParams2Grid();//function to bind data to grid
select event RowCancelingEdit
add the following code
grdTest.EditIndex = -1;
BindParams2Grid();//function to bind data to grid
select event RowUpdating
add the following code
GridViewRow row =grdTest.Rows[e.RowIndex];
TextBox paramvalue = (TextBox)row.FindControl("Textbox1");
TextBox paramname = (TextBox)row.FindControl("Textbox2");
int id = Convert.ToInt32(grdTest.Rows[e.RowIndex].Cells[0].Text);
string query = "UPDATE APPPARAMS SET PARAMNAME='" + paramname.Text + "' AND PARAMAVALUE='" + paramvalue.Text + "' WHERE ID=" + id;
SqlCommand sqlc = new SqlCommand();
sqlc.Connection = new SqlConnection(con);
sqlc.Connection.Open();
sqlc.CommandText = query;
sqlc.ExecuteNonQuery();
sqlc.Connection.Close();
Regards
Bino
www.technix.co.nr
|
|
|
|
|
The following is a sample webservice that will erturn the sum of two numbers. Of late we'll use it in another application facilitating the given Webservice method to be called by the application.
Step 1.
Open devenv->New Website-->ASP.Net Webservice.
Step 2.
This will create a sample Webservice page with a 'Helloworld' sample method created by default.
Lets remove this Helloworld Web method and put a sample method for our use.
[WebMethod]
public int TestSum(int a,int b) {
return (a + b);
}
The above method is just a sample for making it easy to understand. Anycase this is going to be too complicated if someone is using a Webservice,since no application will require to consume a webservice just for summing two numbers.
No lets build this Webservice. Building the Webservice will open up a window with the given method name. Clicking on that will redirect to a page where our input parameters are displayed as text inputs and an 'Invoke' button. Here by inputting the parameters and then clicking on the Invoke button will return the result. Please keep it in mind that this is just a sample interface provided by the Webservice for testing our method and wont even work if the return value is of some other types.
Now the next step is to consume this Webservice. For that what we need to do is create an application and add our Webservice location as Web Reference. Let me detail on this too.
Once we create an application, when we right click on the project in the Solution Explorer, there will be an 'Add Web Reference'. Clicking this will open up a window with a text input for URL. Now what we need to do is copy our Webservice location, ie while we run our Webservice, there will be an address in our address bar. Copy this till the '.asmx' (for example : http://localhost:3003/WebServiceTest/Service.asmx). Paste this in the URL field and click on Go. This will open up our Webservice in the sample browser on the same window. Now what we need to do is, provide a Web reference name(say in this case TestWS,since we need this in the coming steps). This can be any name and click on the 'Add Reference' button. This will create a key in the Web.config file with the given WebService URL.
The next step is to call the defined methods in our webservice from our application. For this first we need to create an object of the given class in the webservice. The object creation step will be like the following.
TestWS.Service test1 = new TestWS.Service();
Response.Write(test1.TestSum(25, 15));
in the above lines of code TestWS is the refernce name we have given for our WebService and Service is the class name inside the Webservice(Service will be the default class name).
For testing purpose we can put these line of code in a button click or something.
Thats it done. Make sure that the Webservice is running if its running thru an ASP.Net Development Server or if thru IIS there is no need to keep the Webservice running.
Regards
Bino
|
|
|
|
|
//Using the following code we can read a directory having a group of
//xml files and reading a given node using Xpath. You can modify
//as per your XML structure. The folder name also should be changed
//accordingly.
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
using System.Collections;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = GetXMLParsedResult("Basic/Discount").ToString();
}
public string GetXMLParsedResult(string XPath)
{
DirectoryInfo dinfo = new DirectoryInfo("D:\\Bino\\ISBN");
ArrayList alFiles = new ArrayList();
int i = 0;
string strXML = "";
foreach (FileInfo finfo in dinfo.GetFiles("*.XML"))
{
alFiles.Add(finfo);
string filename = "D:\\Bino\\ISBN\\" + alFiles[i].ToString();
XmlDocument document = new XmlDocument();
document.Load(filename);
XmlNodeList nlist = document.SelectNodes("/IngramSearchResults/Book/" + XPath);
foreach (XmlNode node in nlist)
{
strXML = strXML + "<br />" + node.InnerText + "------> " + alFiles[i].ToString();
}
i = i + 1;
}
return strXML;
}
//Not using
public string FileContent(string FileName)
{
string file = Server.MapPath(FileName + ".xml");
StreamReader sr;
FileInfo fi = new FileInfo(file);
string File_Content = "";
if (File.Exists(file))
{
sr = File.OpenText(file);
File_Content += sr.ReadToEnd();
sr.Close();
}
return File_Content;
}
}
Regards
Bino
|
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = GetXMLParsedResult("Basic/ISBN");
}
public string GetXMLParsedResult(string XPath)
{
string filename = "D:\\Bino\\ISBN\\0152842861.XML";
XmlDocument document = new XmlDocument();
document.Load(filename);
string strXML="";
XmlNodeList nl = document.SelectNodes("/Results/Book/"+XPath);
foreach (XmlNode node in nl)
{
strXML = strXML + "<br />" + node.InnerText;
}
return strXML;
}
Regards
Bino
|
|
|
|
|
CREATE PROCEDURE [dbo].[test] (
@TestID tinyint,
@TestDesc nvarchar(150)
) AS
SET NOCOUNT ON
INSERT INTO dbo.test1 (
[TestID],
[TestDesc]
) OUTPUT INSERTED.[TestID]
VALUES (
@TestID,
@TestDesc
)
Regards
Bino
|
|
|
|
|
Whether short cut keys were possible in Web application.
The following snippet will give good path.
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" AccessKey="n" AssociatedControlID ="TextBox1"><u>N</u>ame</asp:Label>
<asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox>
<br />
<br />
<asp:Label ID="Label2" runat="server" AccessKey ="a" AssociatedControlID ="TextBox2" ><u>A</u>ge</asp:Label>
<asp:TextBox ID="TextBox2" runat="server" ></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="Click" />
</div>
</form>
Regards
Bino
|
|
|
|
|
SELECT a.a, a.b, b.c, b.d
FROM AA AS a INNER JOIN
OPENROWSET('SQLNCLI', 'test'; 'test'; 'test1',
'select x,y from dbname.dbo.tablename') AS a ON a.aid = b.aid
Syntax
OPENROWSET('provider_name'
{
'datasource';'user_id';'password'
| 'provider_string'
},
{
[catalog.][schema.]object
| 'query'
})
Regards
Bino
|
|
|
|
|
This will help u to click run and type ur shortcut to reach ur routine application in the shortest way possible
goto regedit
navigate to this key
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
add new key
provide the name ex: bino.exe
click on default on the right side pane and click modify.
Now enter the path to your required application....thats it done :->
-- modified at 13:21 Thursday 16th August, 2007
Regards
Bino
|
|
|
|
|
I've been annoyed by this strange error while trying to create a basic Webpart application. I fixed this somehow and i just needed to share this with everyone.
If you are getting an error like this while using webparts
"The specified connectionStringName, 'LocalSqlServer', was not registered."
Run the "aspnet_regsql" application available in
C:\WINDOWS\Microsoft.NET\Framework\{version}\aspnet_regsql.
Provide the database name as aspnetdb(if this db is already available,then u may not get the same error given above.). This will create a new db named "aspnetdb".
Now add the following in web.config
<connectionStrings>
<add name="LocalSqlServer"
connectionString="Data Source=*****\sqlexpress;Initial Catalog=aspnetdb;User ID=sa;password=****;"
providerName="System.Data.SqlClient"/>
</connectionStrings>
now add the following in page load
WebPartManager1.DisplayMode = WebPartManager.DesignDisplayMode;
Thats it, done!!!
http://137.229.174.56:86/FinalProject/Demo.aspx[^]
-- modified at 4:56 Friday 14th September, 2007
Regards
Bino B
www.technix.co.nr
|
|
|
|
|
<a href="http://{Url}">
<xsl:value-of select="Url"/>
</a>
here Url will be the link to the given website
Regards
Bino Bose
|
|
|
|
|
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Refreshed at " +
DateTime.Now.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
#UpdatePanel1 {
width:300px; height:100px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div style="padding-top: 10px">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel</legend>
<asp:Label ID="Label1" runat="server" Text="Panel created."></asp:Label><br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<br />
</div>
</div>
</form>
</body>
</html>
Regards
Bino Bose
|
|
|
|
|