开发者

File upload control not working while running through IIS

This is my coding for the upload to eport to excel...it is working fine when i run

through local in case while running through IIS it is not working.....

This is my code....

protected void btnImport_Click(object sender, EventArgs e)
{
    if (RevenueDumpFileUpload.HasFile)
    {
        string strFilePathOnServer = ConfigurationManager.AppSettings["RevenueDumpFileLocation"];
        String sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath(strFilePathOnServer) + RevenueDumpFileUpload.FileName + ";Extended Properties=Excel 8.0;";
       // RevenueDumpFileUpload.PostedFile.SaveAs(Server.MapPath(strFilePathOnServer) + RevenueDumpFileUpload.FileName);
        OleDbConnection Exlcon = new OleDbConnection(sConnectionString);
        try
        {
            Exlcon.Open();
        }
        catch
        {
            return;
        }
        OleDbCommand 开发者_如何学编程objCmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", Exlcon);
        OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
        objAdapter1.SelectCommand = objCmdSelect;
        objAdapter1.Fill(objDataset1, "XLData");
        methodtosave();
    }
}

How to solve this?


In fact Fileupload will work and should save the file, but there is problem in the connection string when you try to read the uploaded file. It should be the same file path as you are using to save the file.

String sConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=" + strFilePathOnServer + RevenueDumpFileUpload.PostedFile.FileName + ";
Extended Properties=Excel 8.0;";


What type of application is this. Is it a Web Forms app? If so:

What do you mean by local and through IIS? Do you mean on the Server IIS? If you're running the code on the server and it's not working then you are trying to force the server to do something it's not allowed to do.

For security reasons you shouldn't be accessing Excel on the server from an outside source. What you can do, if this is a Web Forms app, is use java script and an active x control to access the client's excel and write client side java script to save the file to the correct directory. There are plenty of examples online, use Google, to do this. I recently had to do this for 2 Web Applications at work.

If not then this might not be your problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜