M
Morris Neuman
Hi,
I have a web page that allows a user to select an excel file using the
FileUpload Control (BrowseFileToUpload), then using a button's onclick
command (ButtonUploadFile_Click), uploads the selected file and saves it
using a preset name ("ExcelImportODS-" + u.UserName + ".xls") in a folder on
the webserver.
Is there anyway to tell how many rows were in the uploaded file?
My upload is as follows:
protected void ButtonUploadFile_Click(object sender, EventArgs e)
{
//Uploads the file selected by the user using the Browse button of
the fileupload control(CALLMaster\Data\TestImport.xls)
//and uploads to web server using new name
ExcelImportODS-{webaccountname].xls.
if (BrowseFileToUpload.HasFile)
{
try
{
String strFileExt =
System.IO.Path.GetExtension(BrowseFileToUpload.PostedFile.FileName);
if (strFileExt == ".xls")
{
try
{
String strSettingSelected = "";
if (RadioButtonListImportSetting.SelectedIndex == 1)
{
strSettingSelected = "Custom Settings";
}
else
{
strSettingSelected = "Fixed Settings";
}
MembershipUser u =
Membership.GetUser(User.Identity.Name);
//You can use the u.xxxxx method to access various
user info. ex. u.email or u.lastactivitydate
//use intelisense for options.
BrowseFileToUpload.SaveAs(Server.MapPath("~/ImportData/ExcelImportODS-" +
u.UserName + ".xls"));
//LabelUploadStatus.Text = "<br>Uploaded File Name:
" + BrowseFileToUpload.PostedFile.FileName + "<br>" + "Type: " +
BrowseFileToUpload.PostedFile.ContentType + " File Size: " +
BrowseFileToUpload.PostedFile.ContentLength + "kb FileExtension: " +
strFileExt + "<br>";
LabelUploadStatus0.Text = "<br>Uploaded File Name: "
+ BrowseFileToUpload.PostedFile.FileName + "<br>" + " with " +
strSettingSelected + "<br>";
PanelBrowseUpload.Visible = false;
PanelViewImport.Visible = true;
}
catch (Exception ex)
{
LabelUploadStatus.Text = "Upload Error: " +
ex.Message.ToString();
}
}
else
{
LabelUploadStatus.ForeColor = System.Drawing.Color.Red;
LabelUploadStatus.Text = "<br> * File Type Error: File
must be .xls. File not uploaded.";
}
}
catch (Exception ex)
{
LabelUploadStatus.Text = "Error: " + ex.Message.ToString();
}
}
else
{
LabelUploadStatus.Text = "Please select a file to upload";
}
}
I have a web page that allows a user to select an excel file using the
FileUpload Control (BrowseFileToUpload), then using a button's onclick
command (ButtonUploadFile_Click), uploads the selected file and saves it
using a preset name ("ExcelImportODS-" + u.UserName + ".xls") in a folder on
the webserver.
Is there anyway to tell how many rows were in the uploaded file?
My upload is as follows:
protected void ButtonUploadFile_Click(object sender, EventArgs e)
{
//Uploads the file selected by the user using the Browse button of
the fileupload control(CALLMaster\Data\TestImport.xls)
//and uploads to web server using new name
ExcelImportODS-{webaccountname].xls.
if (BrowseFileToUpload.HasFile)
{
try
{
String strFileExt =
System.IO.Path.GetExtension(BrowseFileToUpload.PostedFile.FileName);
if (strFileExt == ".xls")
{
try
{
String strSettingSelected = "";
if (RadioButtonListImportSetting.SelectedIndex == 1)
{
strSettingSelected = "Custom Settings";
}
else
{
strSettingSelected = "Fixed Settings";
}
MembershipUser u =
Membership.GetUser(User.Identity.Name);
//You can use the u.xxxxx method to access various
user info. ex. u.email or u.lastactivitydate
//use intelisense for options.
BrowseFileToUpload.SaveAs(Server.MapPath("~/ImportData/ExcelImportODS-" +
u.UserName + ".xls"));
//LabelUploadStatus.Text = "<br>Uploaded File Name:
" + BrowseFileToUpload.PostedFile.FileName + "<br>" + "Type: " +
BrowseFileToUpload.PostedFile.ContentType + " File Size: " +
BrowseFileToUpload.PostedFile.ContentLength + "kb FileExtension: " +
strFileExt + "<br>";
LabelUploadStatus0.Text = "<br>Uploaded File Name: "
+ BrowseFileToUpload.PostedFile.FileName + "<br>" + " with " +
strSettingSelected + "<br>";
PanelBrowseUpload.Visible = false;
PanelViewImport.Visible = true;
}
catch (Exception ex)
{
LabelUploadStatus.Text = "Upload Error: " +
ex.Message.ToString();
}
}
else
{
LabelUploadStatus.ForeColor = System.Drawing.Color.Red;
LabelUploadStatus.Text = "<br> * File Type Error: File
must be .xls. File not uploaded.";
}
}
catch (Exception ex)
{
LabelUploadStatus.Text = "Error: " + ex.Message.ToString();
}
}
else
{
LabelUploadStatus.Text = "Please select a file to upload";
}
}