2016-08-15 1 views
0

에 업로드시 텍스트 파일을 구문 분석 서버내가 필요 어디 웹 프로젝트를 .NET

업로드되는 파일은 각 SQL 문이 세미콜론 (;)으로 끝나는 .sql 파일입니다. 아이디어는 행당 1 개의 SQL 문을 구문 분석하는 것입니다. (소스 파일은 20 개의 행에 걸쳐있는 SQL 문을 가질 수 있지만 20 행의 세미콜론은 명령문이 한 행에 들어가는 것을 의미합니다.

이것은 대부분 새로운 부분입니다. 버튼을 사용하여 파일을 검색하고이를 로컬 드라이브에 저장합니다. 나중에 정확한 저장 위치에 대해 걱정할 것이지만 위에서 설명한대로 .sql 파일을 구문 분석하는 방법에 관심이 있습니다. 내 코드에

감사

HTML :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="FileUpload.WebForm1" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
</head> 
<body> 
    <%-- <form id="form1" runat="server"> --%> 
     <form id="form2" runat="server"> 
    <asp:FileUpload id="FileUploadControl" runat="server" /> 
    <asp:Button runat="server" id="UploadButton" text="Upload" onclick="UploadButton_Click" /> 
    <br /><br /> 
    <asp:Label runat="server" id="StatusLabel" text="Upload status: " /> 


</form> 
</body> 
</html> 
,451,515,

CODE :

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

namespace FileUpload 
{ 
    public partial class WebForm1 : System.Web.UI.Page 
    { 
     protected void Page_Load(object sender, EventArgs e) 
     { 

     } 

     protected void UploadButton_Click(object sender, EventArgs e) 
     { 
      try 
      { 
       string filename = Path.GetFileName(FileUploadControl.FileName); 
       FileUploadControl.SaveAs(Server.MapPath("~/") + filename); 
       StatusLabel.Text = "Upload status: File uploaded!"; 
      } 
      catch (Exception ex) 
      { 
       StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message; 
      } 
     } 
    } 
} 
+0

각 요소는 세미콜론에서 반환 된 문자열, 문자열 배열 작업이 반환 (사항 String.split를) 분할 파일 (File.ReadAllText을) 읽기 너의 '단일 행' – Steve

답변