What is the difference between Server.Transfer and
Response.Redirect? Why would you choose one over the other?
Answer Posted / a
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.Runtime.InteropServices.ComTypes;
using System.Data.OleDb;
using System.IO;
public partial class ReadExcel : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
string strFilePath = @"D:\Development\Test.xlsx";
string strBatchPath = @"D:\Development\test.txt";
try {
string strConnectionString = string.Empty;
//strConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
strFilePath + @";Extended Properties=""Excel
8.0;HDR=YES;IMEX=1""";
strConnectionString =
@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
strFilePath + @";Extended Properties=""Excel 12.0
Xml;HDR=YES;IMEX=1""";
OleDbConnection cnCSV = new OleDbConnection
(strConnectionString);
cnCSV.Open();
OleDbCommand cmdSelect = new OleDbCommand
(@"SELECT * FROM [Sheet1$]", cnCSV);
OleDbDataAdapter daCSV = new OleDbDataAdapter();
daCSV.SelectCommand = cmdSelect;
DataTable dtCSV = new DataTable();
daCSV.Fill(dtCSV);
cnCSV.Close();
daCSV = null;
StreamWriter sr = File.AppendText(strBatchPath);
string cmd = string.Empty;
for (int i = 0; i < dtCSV.Rows.Count; i++) {
cmd = "xcopy /Y \"" + dtCSV.Rows[i][0]
+ "\" " + "\"D:/\"";
WriteText(cmd, sr);
}
sr.Close();
} catch (Exception ex) {
} finally {
}
}
public void WriteText(string message, TextWriter tr) {
tr.WriteLine(message);
tr.Flush();
}
}
| Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
What is distributed system in asp.net?
What is a web api? Which protocol is used in a web api?
Explain Authentication mechanism in dotnet
What is different authentication mechanisms used in ASP.NET?
Describe the difference between inline and code behind - which is best in a?
Which methods validate all the controls on a page?
What is cached data phone?
What is session handling in a webfarm, how it can work with its limits?
What is State Management in .Net and how many ways are there to maintain a state in .Net? What is view state?
What is cross page posting? How is it done?
Explain why it is useful to use mvc instead of webforms? : asp.net mvc
Am not able to move the controls on the form freely in asp.net 3.5 even though I selected the position as relative or absolute for those controls. What should I do to overcome this?
What are the advantages of using session?
How to implement Authentication and Authorization?
Where sessions are stored?