2013-04-02 6 views
1

내가 그것을 채우는 DBF 파일 등을 생성하기 위해 아래의 코드를 사용립니다. 문제는 파일 이름이 8 자 이하로 잘리는 것입니다. 왜 또는 어떻게 전체 이름을 유지하는 아이디어?DBF 파일 이름은 모든 것이 잘 작동

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+path+";Extended Properties=dBase IV"; 
OleDbConnection connection = new OleDbConnection(connectionString); 
     connection.Open(); 
cmd.CommandText = @"CREATE TABLE calendfull(
           date1 datetime , 
           day1 int , 
           month1 int , 
           year1 int , 
           dow int , 
           endmonth int 
           )"; 

      cmd.ExecuteNonQuery(); 

    foreach (DataRow row in calend.Rows) 
      { 
       day = Convert.ToInt32(row["day"]); 
       year = Convert.ToInt32(row["year"]); 
       month = Convert.ToInt32(row["month"]); 
       dow = Convert.ToInt32(row["dow"]); 
       endmonth = Convert.ToInt32(row["endmonth"]); 
       date1 = Convert.ToDateTime(row["date1"]); 

       cmd.CommandText = @"insert into calendFull values ('" + date1 + "'," + day + "," + month + "," + year + "," + dow + "," + endmonth + ")"; 
       cmd.ExecuteNonQuery(); 
      } 
+0

코드의 그 ** 파일을 생성합니까? ** 여기에 뭔가 빠졌습니까? –

+0

내가 만들고 – SKGeek

답변

0

DBF 파일 이름은 8.3 명명 사양을 따르므로 이름은 8자를 초과 할 수 없습니다.

잠깐만, 이름이 8 자 이상인 dbf 파일을 보았습니다.

예, 허용되지만 명령 프롬프트에서 파일 이름과 같은 실제 이름을 사용할 수 있습니다. 예 : largef~1

어떻게 읽을 수 있습니까? 당신은 코드 KERNEL32.DLL 여기

이다 사용하여 짧은 이름을 얻어야한다 :

public string GetShortFileName(string fileDirectory, string fileNameWithExtension) 
    { 
     StringBuilder temp = new StringBuilder(255); 

     string path = System.IO.Path.Combine(fileDirectory, fileNameWithExtension); 

     int n = GetShortPathName(path, temp, 255); 

     if (n == 0) 
      throw new NotImplementedException(); 

     string extension = System.IO.Path.GetExtension(path); 

     return ((temp.ToString().Split('\\')).Last()).ToLower();//.Replace(extension, string.Empty); 
    } 

    [System.Runtime.InteropServices.DllImport("kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)] 
      public static extern int GetShortPathName(
     [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]  
     string path, 
     [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)]  
     StringBuilder shortPath, 
     int shortPathLength); 
+1

가'kernel32.dll'를 사용하여 짧은 이름을 돌려 충전, 전체 코드를 포함 할 수있는 질문을 업데이트? 저는 dBASE와 FoxPro로 수년간 함께했습니다. 파일 이름은 수, 그리고 있으며, 이상 8 자, 및 Windows에서 전체 이름으로 참조 할 수 있습니다. 이 사진에 훨씬 더 뭔가가있다 - 즉, OP에서 제공하는 코드가 파일 또는 이름과는 아무 상관이 없기 때문에 분명히 표시되지 ***의 *** –

+1

나는'dbf' 파일로 작업했습니다. 년도. 그리고 나는이 문제를 보았다. 당신은 그것을 검색 할 수 있습니다 (dbf 파일 이름 제한) 그리고 내가 사실인지 아닌지 확인하십시오. –

+1

@MichaelPerrenoud이 참조 (http://social.msdn.microsoft.com/Forums/en-US/visualfoxprogeneral/thread/fcb3505d-a6fe-400c-9345-eb75fd8f1747/). 'Microsoft.Jet.Oledb'를 사용할 때 일어나는 것처럼 보입니다. –

0
 const string connectionString = @"Provider = vfpoledb; Data Source = {0}; Collating Sequence = general;"; 
     OleDbConnection conn = new OleDbConnection(string.Format(connectionString, dirName)); 
     conn.Open(); 
     OleDbCommand cmd = new OleDbCommand(string.Format("select * from {0}", fileName), conn) 

변경을 OLEDB 공급자 :

Use Microsoft OLE DB Provider for Visual FoxPro 9.0