Wednesday, August 13, 2008
Import Excel into Dataset
1. Upload th excel file into Application Server (IIS Site Folder)
FileUpload1.SaveAs(Server.MapPath("~/xcel/") + FileUpload1.FileName);
2. Connect excel sheet, read data and import into a dataset.
DataSet myDataset = new DataSet();
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" + FilePath + @";
Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1""";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable DTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
//here the code will read sheet from spreadsheet with any name --generic
OleDbDataAdapter myData = new OleDbDataAdapter
(@"SELECT * FROM [" +
DTable.Rows[0]["TABLE_NAME"].ToString() + "]", conn);
//
myData.Fill(myDataset);
That is the end. The code is not restricted or limited to any name of the sheet in the excel spread sheet. ....
-::-
Friday, August 01, 2008
CSS text-align:center not working in FireFox (FF)
body
{
text-align: center;
}
body
{
text-align: -moz-center;
}
-::-
Tuesday, July 29, 2008
Javascript to accept only numeric values
"onkeypress" event.
function onlyInteger(evt)
{
evt = window.event;
var charCode = evt.keyCode;
if (charCode > 31 && (charCode <> 57)) {
status = "This field accepts numbers only.";
return false;
}
status = "";
return true;
}
-::-
Tuesday, March 25, 2008
SQL Server 2005 Express DTS Wizard - Export/Import Utiltity
http://www.microsoft.com/downloads/info.aspx?na=46&p=16&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=d09c1d60-a13c-4479-9b91-9e8b9d835cdc&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f4%2f4%2fd%2f44dbde61-b385-4fc2-a67d-48053b8f9fad%2fSQLServer2005_DTS.msi
Monday, March 17, 2008
Tuesday, March 11, 2008
Error Creating Control - Formdigest1. Failure decoding embedded permission set object
"Error Creating Control - Formdigest1. Failure decoding embedded permission set object"
while using the Formdigest control.
Formdigest controls is to be used in the pages of web application where in you query and update the sharepoint data via object ibrary. Formdigest validates the security of the page while submitting a request.
Resolution
To make it work, the web apps should be deployed in the same site, i mean in the same context.
-::-
How to enable inline coding in MOSS 2007 or WSS 3.0 Custome aspx pages ?
<PageParserPath VirtualPath="/<>/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>
The "PageParserPaths" tags would be already existing in web.config. All you need to do is to add the code in between to specify your folders to execute the C# script.
- :: -
Sunday, August 12, 2007
How to pass array from ASP.Net to Javascript?
To acheive this do as follows:-
- Prepare the string of values seperated by commas, say string ArrayString = 'Hythem', 'Apple','Banana'
- Create the array while passing the values to the javascript
See the code below:-
string ArrayString = 'Hythem', 'Apple','Banana';
ntxtAmt.Attributes.Add("onkeyup", "javascript:testme(new Array(" + ArrayString + ");");
-::-
Saturday, July 21, 2007
How to retrieve the blob object in WinForms to physical location with "Binary Streaming" enabled ?
SqlConnection Conn = new SqlConnection("<>");
SqlCommand Cmd = new SqlCommand("select docobject, filetype,docname from documents where docid = 23", Conn);
Cmd.CommandType = CommandType.Text;
Conn.Open();
SqlDataReader Reader = Cmd.ExecuteReader(CommandBehavior.CloseConnection);
//
string DocumentName = null;
FileStream FStream = null;
BinaryWriter BWriter = null;
//
//
//
byte[] Binary = null;
const int ChunkSize = 100;
int SizeToWrite = 0;
MemoryStream MStream = null;
//
while (Reader.Read())
{
DocumentName = Reader["docname"].ToString();
// Create a file to hold the output.
FStream = new FileStream(@"c:\" + DocumentName, FileMode.OpenOrCreate, FileAccess.Write);
BWriter = new BinaryWriter(FStream);
Binary = (Reader["docobject"]) as byte[];
SizeToWrite = ChunkSize;
MStream = new MemoryStream(Binary);
//
for (int i = 0; i < Binary.GetUpperBound(0) - 1; i = i + ChunkSize)
{
if (i + ChunkSize >= Binary.Length) SizeToWrite = Binary.Length - i;
byte[] Chunk = new byte[SizeToWrite];
MStream.Read(Chunk, 0, SizeToWrite);
BWriter.Write(Chunk);
BWriter.Flush();
}
BWriter.Close();
FStream.Close();
}
FStream.Dispose();
}
Tuesday, July 10, 2007
Add image to ASP.Net 2.0 Menu navigation control
To map image with a site map node, add a custom property, say, "menuImage" in the sitemapnode tag as below
<siteMapNode url="~/pages/wemployee.aspx" title=":: Employees" description="" menuImage="~/Images/viewdetail.gif" />
Now, in the code behind, add the code below:-
protected void Menu1_MenuItemDataBound(object sender, MenuEventArgs e)
{
e.Item.ImageUrl = ((SiteMapNode)e.Item.DataItem)["menuImage"];
}
Infact, you can have a harcoded image path as well.
HTH
-::-
Tuesday, July 03, 2007
"Error in File < Path..>\ASPNET\LOCALS~1\Temp\Employees {BBE0A87A-CFF9-4682-A6AD-B0E256CF4793}.rpt:" Crystal Report error in ASP.Net 2.0
"Error in File C:\DOCUME~1\..\ASPNET\LOCALS~1\Temp\Employees {BBE0A87A-CFF9-4682-A6AD-B0E256CF4793}.rpt: Get page number for group failed" while working with Crystal Report in ASP.Net 2.0 ?
This error will occur when you try a postback in the .net page by a tree node click or so. And the reason behind is while postback, report is not able to find the data.
Resolution
To avoid this error, enable the caching by making the prOperty of CrystalReportSource "Enable Caching = true".
HTH
-::-
Tuesday, June 19, 2007
HTML printing with custom page format
This is simply achieved with CSS. The solution is as follows.
Defined two sets of CSS for the page targeting "Print" and "Screen". See the example below.
<style type="text/css">
@media screen{
body {color:Red; }
td{font-size:14px;}
.noprint{display:block !important;}
}
@media print {
body {fcolor:Blue;}
td{font-size:7px;}
.noprint{display:none;}
}
</style>
and the page is
<form id="form1" runat="server">
<div style="text-align: center;">
<table id="tblParent" style="width: 90%">
<tr class="noprint">
<td>
This is just a demonstration of how to make HTML printing</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr class="noprint">
<td style="text-align: right">
<a href="#" onclick="window.print()">Print</a> <a href="#" onclick="window.close()">Close</a>
</td>
</tr>
<tr>
<th>
Employee Informations</th>
</tr>
<tr>
<td>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<table id="tblEmployee" style="width: 100%">
<tr>
<td style="width: 5%;">
</td>
<td style="width: 30%;">
</td>
<td style="width: 5%;">
</td>
<td style="width: 60%;">
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
Last Name</td>
<td>
:</td>
<td align="left">
<%# Eval("LastName") %>
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
First Name</td>
<td>
:</td>
<td align="left">
<%# Eval("firstname") %>
</td>
</tr>
<tr>
<td>
</td>
<td align="left">
Title</td>
<td>
:</td>
<td align="left">
<%# Eval("title") %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</table>
</div>
</form>
Here the section of the page with class .noprint is displayed while displaying on the "screen" and hidden while printing, say buttons and other items
-::-
Sunday, June 17, 2007
URL rewriting in ASP.Net 2.0! Purpose and how to?
URL rewriting is the process of intercepting an incoming Web request and automatically redirecting it to a different URL.
Creating data-driven ASP.NET websites often results in a single Web page that displays a subset of the database's data based on querystring parameters. For example, in designing an e-commerce site, one of your tasks would be to allow users to browse through the products for sale. To facilitate this, you might create a page called displayCategory.aspx that would display the products for a given category. The category's products to view would be specified by a querystring parameter. That is, if the user wanted to browse the Widgets for sale, and all Widgets had a had a CategoryID of 5, the user would visit: http://yousite.com/displayCategory.aspx?CategoryID=5.
There are two downsides to creating a website with such URLs. First, from the end user's perspective, the URL http://yousite.com/displayCategory.aspx?CategoryID=5 is a mess. Usability expert Jakob Neilsen recommends that URLs be chosen so that they:
- Are short.
- Are easy to type.
- Visualize the site structure.
- "Hackable," allowing the user to navigate through the site by hacking off parts of the URL.
I would add to that list that URLs should also be easy to remember. The URL http://yousite.com/displayCategory.aspx?CategoryID=5 meets none of Neilsen's criteria, nor is it easy to remember. Asking users to type in querystring values makes a URL hard to type and makes the URL "hackable" only by experienced Web developers who have an understanding of the purpose of querystring parameters and their name/value pair structure.
A better approach is to allow for a sensible, memorable URL, such as http://yoursite.com/products/Widgets. By just looking at the URL you can infer what will be displayed—information about Widgets. The URL is easy to remember and share, too. I can tell my colleague, "Check out yoursite.com/products/Widgets," and she'll likely be able to bring up the page without needing to ask me again what the URL was. (Try doing that with, say, an Amazon.com page!) The URL also appears, and should behave, "hackable." That is, if the user hacks of the end of the URL, and types in http://yoursite.com/products, they should see a listing of all products, or at least a listing of all categories of products they can view.
How to configure URL rewriting in asp.net 2.0?Add the following code in web.config with proper mapping informations.
<?xml version="1.0" ?">
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<system.web">
<urlmappings enabled="true"">
<add url="~/Autos.aspx" mappedurl="~/Default.aspx?category=autos">
<add url="~/Games.aspx" mappedurl="~/Default.aspx?category=games">
</urlmappings>
</system.web>
</configuration>
Now, add the mapping in the ISAPI filter of IIS.
Say, if you use the extention ".mspx", add the extension to the ISS pointing to C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll. That means, whatever request with extension .mspx should be handled by aspnet worker thread.
HTH
Sunday, June 03, 2007
"The server instance specified was not found" error message when you perform an operation on a virtual server in Windows SharePoint Services
The server instance specified was not found. Please specify the server's address and port.
eg:-
SPSite MySite = new SPSite(http://spsite);
String SiteURL = MySite.Url.ToString ();
Cause
This may occur due to the fact that virtual server of the site is assigned a specific IP address (instead of "All Unassgined" configuration) and server name is mapped in Domain Control (DNS). In these cases, WSS will not query DNS to resolve the host name since the hostname is not mapped in the metabase.
Resolution
Assign a host header name to the IP address that is configured for the virtual server in IIS. By doing so, Windows SharePoint Services can map the virtual server to the host name. To assign a host header name for a virtual server in IIS, follow these steps:
- Start Internet Information Services (IIS) Manager.
- Expand ServerName, and then expand Web Sites.
- Right-click the Web site that you want, and then click Properties.
- Click the Web Site tab, and then under Web site identification, click Advanced.
- Under Multiple identities for this Web site, click Add.
- In the Add/Edit Web Site Identification dialog box, specify an IP address, TCP port, and host header value, and then click OK
- Click OK, and then click OK.
- If the IP address of the virtual server in IIS is set to All Unassigned, perform the operation on the virtual server by using the server name.
- Perform the operation on the virtual server by using the IP address that is assigned to the virtual server.
Friday, June 01, 2007
Error on security tab : Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion' in ASP.Net 2.0 Web Administration Tool
Error while configuring ASP.Net 2.0 membership provider with Web Administration tool
You may receive the following error while configuring the .net 2.0 membership provider.
Error on security tab : Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion' in ASP.Net 2.0 Web Administration Tool
Resolution
You must have to create the SQL schema in the database you're going to use for membership. To do this, you can run aspnet_regsql from the v2.0 directory. That'll open up a wizard and walk you through the steps to create the SQL stored procs and such that are needed for the security and membership stuff-::-
Thursday, May 31, 2007
How to handle hidden columns/values in gridview 2.0?
It is always a "Fact" that we are not supposed to disclose any confidential data to the browser, whether it is a primary key or not. At the same time we may need those values for further processing of the page logic. In datagrid (.net 1.1), we always used to get the hidden values in the viewstate and we can make use of those values in client side script.
Resolution
However, the situation is changed now!. Due to security breach, microsoft has come up with new term "DataKeys" in order to hide the hidden fields forever (from rendering). You cannot see the hidden column values in View State. At the sametime, you can have multiple datakeys for a particular gridview control. Doing so, you can extract the values of those fields against each row, but only from code behind as it is not rendered in the browser.
You can access the values as below :
GridView.DataKeys[i].Values[j].ToString()
where 'i' represent the rownumber and 'j' represent the index of DataKeys (defined).
-::-
Wednesday, March 14, 2007
Is cross database referential integrity possible ?
And as per the third party tool, remote-keys this could be achieved. But it is more like a work around, achieving the same programmatically (DDL statements in triggers)
Hence to my knowledge, it is not possible in SQL where as the feature is available in SYBASE. Any different thought ?
What developer says?
http://msdn2.microsoft.com/en-us/library/ms189799.aspx#
http://www.thescripts.com/forum/thread584690.html
What Third Party says?
http://www.remote-keys.com/product.aspx
-::-
Wednesday, February 21, 2007
IE Web User Controls deployment in SharePoint 2003 - How to?
Steps
1. Add the controls in .ascx (used for web parts)
2. While deploying, copy the Microsoft.Web.UI.WebControls.dll to the bin of WSS root
3. Deploy the above dll in GAC (if required)
4. Run the Build.Bat file from C:\Program Files\IE Web Controls (installation folder). While doing this, care should be taken for CSC.exe location - either run it from VS.Net Command prompt (after switiching to the above location) or include the path of CSC.exe in the "Environment Variables" of system. This will generate a \build\Runtime folder with script file required for the controls
5. Copy the above folder to the root of WSS
6. Exclude the path for the above folder, say webctrl_client (only type the folder name as it is in the root folder) by configuring the virutal server (use SharePoint Central Administration page)
Now it will work!!
-::-
Tuesday, February 20, 2007
How do we generate XSD in VS.Net for reporting from a stored procedure containing #temp tables (local) ?
Resolution
1. Comment the lines containting temp tables in sp
2. Generate .xsd file in .net IDE
3. Uncomment the comments
Yeah!!! It worked
-::-
Monday, February 12, 2007
How to consume a Share Point web service in ASP.Net web ?
Follow the steps below:
1. Add web reference in the IDE with URL of SPS site
2. Create a proxy class with WSDL.exe utility (available in the VS.Net Tools menu)
Go to command prompt and type as below
wsdl /out: c:\ProxyClass.cs http://server:90/_vti_bin/lists.asmx
Find more options of wsdl here
3. Consume the webservice via proxy class (shouled be added to the project)
4. Now you should get all the published methods in web service via proxy class
-::-