Hi,
As per my understand your question is looks like upload the excel file and display the sheets in that excel and then that excel to be stored in particular folder...
right...?
but directly you ask coding this is not a correct way . If your asking coding some one given the code..
But you can't understand the logic of the code...
First of all you try by your self , any error came you search by your self then also your doubt is not clear then only you post the questions on this site ...
this is the source code
<table>
<tr>
<td align="center" colspan="3">
<asp:label id="Label1" runat="server" text="Drawing Schedule" cssclass="PageHead" xmlns:asp="#unknown"></asp:label>
</td>
</tr>
<tr>
<td align="right">
Excel File :
</td>
<td align="left">
<asp:fileupload id="FileUpload1" width="50%" runat="server" xmlns:asp="#unknown" />
<asp:label id="lblmsg" runat="server" text="" xmlns:asp="#unknown"></asp:label>
<asp:button id="btnGetExcelSheetList" runat="server" onclick="btnGetExcelSheetList_Click" xmlns:asp="#unknown">
Text="Get Excel Sheet List" />
<br />
</asp:button></td>
</tr>
<tr>
<td align="right" valign="top" colspan="" class="style1">
<asp:label id="lblsheet" runat="server" text="Sheet Name : " xmlns:asp="#unknown"></asp:label>
</td>
<td valign="top" colspan="" class="style6">
<asp:dropdownlist id="ddlSheet" runat="server" autopostback="True" visible="False" xmlns:asp="#unknown">
SkinID="DropDownListSkin"
OnSelectedIndexChanged="ddlSheet_SelectedIndexChanged">
</asp:dropdownlist>
<br />
<br />
</td>
</tr>
</table>
In your CodeBehind:
private void Get_Sheets()
{
OleDbConnection oconn = null;
DataTable dt = null;
try
{
string FilePath = string.Empty;
string FileName = string.Empty;
if (FileUpload1.HasFile)
{
FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string Extension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string FolderPath = ConfigurationManager.AppSettings["PRPOFolder"];
FilePath = Server.MapPath(FolderPath + FileName);
ViewState["FilePath"] = FilePath;
ViewState["FileName"] = FileName;
FileUpload1.SaveAs(FilePath);
}
oconn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FilePath + ";Extended Properties=Excel 8.0");
oconn.Open();
dt = null;
dt = oconn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (dt == null)
{
}
String[] sheet = new String[dt.Rows.Count];
int i = 0;
foreach (DataRow dr in dt.Rows)
{
sheet[i] = dr["TABLE_NAME"].ToString();
i++;
}
string[] a = sheet;
int j = 0;
if (a != null && a.Length > 0)
{
ddlSheet.Visible = true;
lblsheet.Visible = true;
for (j = 0; j < a.Length; j++)
{
ddlSheet.Items.Add(a[j]);
}
ddlSheet.Items.Insert(0, "<--- Select Excel Sheet --->");
}
else
{
ddlSheet.Visible = false;
lblsheet.Visible = false;
}
}
catch (Exception ex)
{
}
finally
{
if (oconn != null)
{
oconn.Close();
oconn.Dispose();
}
if (dt != null)
{
dt.Dispose();
}
}
}
protected void btnGetExcelSheetList_Click(object sender, EventArgs e)
{
ddlSheet.Items.Clear();
Get_Sheets();
}