2014-04-29 1 views
0

엑셀 시트에 DataTable을 작성하고 클라이언트 컴퓨터에서 열어 보겠습니다. 클라이언트가 선호하는 위치에 파일을 저장하게하십시오. 파일을 만들고 하이브에 저장했습니다. 클라이언트 컴퓨터에서 열 수는 없습니다. 나는 excel을 위해서 interop.dll을 사용하고 있습니다.하이브에 저장 한 후 클라이언트 컴퓨터에서 Excel 파일을 엽니 다.

excelWorkBook.Saved = true; 
SPSecurity.RunWithElevatedPrivileges(delegate() 
{ 
    excelWorkBook.SaveCopyAs(filename); 
}); 

excelWorkBook.Close(Missing.Value, Missing.Value, Missing.Value); 
excelWorkBook = null; 
excelApp.Quit(); 

클라이언트 컴퓨터에서 저장된 엑셀 시트를 열고 클라이언트가 자신의 위치에 저장 한 후 하이브에서 파일을 삭제하고 싶습니다.

도와주세요.

답변

1

시도해보십시오. 그러면 파일 저장 대화 상자가 열립니다. 그래서 사용자는 자기가 원하는 이제까지 파일을 저장할 수 있습니다 ..

try 
     { 
      string XlsPath = Server.MapPath(@"~/Resources/test.xls");// give ur file path here (where it is stored, in ur case ur Hive path) 
      FileInfo fileDet = new System.IO.FileInfo(XlsPath); 
      Response.Clear(); 
      Response.Charset = "UTF-8"; 
      Response.ContentEncoding = Encoding.UTF8; 
      Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(fileDet.Name)); 
      Response.AddHeader("Content-Length", fileDet.Length.ToString()); 
      Response.ContentType = "application/ms-excel"; 
      Response.WriteFile(fileDet.FullName); 
      Response.End(); 
     } 
     catch (Exception ex) 
     { 
      throw ex; 
     } 

을이이 SharePoint 웹 파트와 함께 할 수 방법입니다

try 
     { 
      using (SPSite site = new SPSite(SPContext.Current.Web.Url)) 
      { 
       SPWeb currentWeb = site.RootWeb; 
       currentWeb.ParserEnabled = false; 
       SPFile spFile = currentWeb.GetFile(@"/Shared%20Documents/test.xls"); // ur documet url saved in document library 
       string localFileName = Path.Combine(@"c:\Users\anbuj\Documents\Backup", string.Format("{0}.xls","tempfile")); // tenpFilePath is where u wanna save ur file 
       SPSecurity.RunWithElevatedPrivileges(delegate() 
       { 
        FileStream outStream = new FileStream(localFileName, FileMode.Create); 
        byte[] fileData = spFile.OpenBinary(); 
        outStream.Write(fileData, 0, fileData.Length); 
        outStream.Close(); 
       } 
        ); 

      } 
     } 
     catch(Exception ex) 
     { 
      throw ex; 
     }