本文介绍了找不到路径'E:\Projects \Faculty Schedule SMS \ ~UploadedExcel \ 04012013_0840SS.xls'的一部分。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

读取并优化数据并将其更新到数据库。



代码如下;



Read and excel data and updated it to the DataBase.

Code as follows;

 using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.IO;


public partial class _Default : System.Web.UI.Page 
{
    SqlConnection conn = new SqlConnection("Data Source=INDIA;Initial Catalog=HIMTTESTing;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    
    protected void btnUpload_Click1(object sender, EventArgs e)
    {

        if ((txtFilePath.HasFile))
        {

            SqlConnection conn = new SqlConnection();
            SqlCommand cmd = new SqlCommand();
            SqlDataAdapter da = new SqlDataAdapter();
            DataSet ds = new DataSet();
            string query = null;
            string connString = "";
            string strFileName = DateTime.Now.ToString("ddMMyyyy_HHmmSS");
            string strFileType = System.IO.Path.GetExtension(txtFilePath.FileName).ToString().ToLower();

            //Check file type

            if (strFileType == ".xls" || strFileType == ".xlsx")
            {
                txtFilePath.SaveAs(Server.MapPath("~UploadedExcel/" + strFileName + strFileType));
            }
            else
            {
                lblMessage.Text = "only excel files allowed";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Visible = true;
                return;
            }
            string strNewPath = Server.MapPath("~UploadedExcel/" + strFileName + strFileType);

            //Connection String to Excel Workbook
            if (strFileType.Trim() == ".xls")
            {
                //connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strNewPath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
                connString = "Data Source=INDIA;Initial Catalog=HIMTTESTing;Integrated Security=True" + strNewPath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";

            }
            else if (strFileType.Trim() == ".xlsx")
            {

             connString = "Data Source=INDIA;Initial Catalog=HIMTTESTing;Integrated Security=True" + strNewPath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
            }
            //query = "select * from Tb_SMS_Faculty_Schedule";
              query = "select * from 180612   FACULTY SCHEDULE POST";

            //Create the connection object
            conn = new SqlConnection(connString);
            if (conn.State == ConnectionState.Closed) conn.Open();
            cmd = new SqlCommand(query, conn);
            da = new SqlDataAdapter(cmd);
            ds = new DataSet();
            da.Fill(ds);

            grvExcelData.DataSource = ds.Tables[0];
            grvExcelData.DataBind();
            lblMessage.Text = " data retrieved successfully! TOtal Records:" + ds.Tables[0].Rows.Count;
            lblMessage.ForeColor = System.Drawing.Color.Green;
            lblMessage.Visible = true;

            da.Dispose();
            conn.Close();
            conn.Dispose();
        }

        else
        {
            lblMessage.Text = "Please select an excel file first";
            lblMessage.ForeColor = System.Drawing.Color.Red;
            lblMessage.Visible = true;
        }

    }
}


当我收到如下错误时
;



无法找到路径'E:\Projects \Faculty Schedule SMS \ ~UploadedExcel \ 04012013_0840SS.xls''的一部分。



请帮帮我。如何解决这个错误对我有帮助。


when i got the error as follows;

Could not find a part of the path ''E:\Projects\Faculty Schedule SMS\~UploadedExcel\04012013_0840SS.xls''.

please help me. how to solve that error help me.

推荐答案



这篇关于找不到路径'E:\Projects \Faculty Schedule SMS \ ~UploadedExcel \ 04012013_0840SS.xls'的一部分。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 13:06