跳到主要內容

發表文章

目前顯示的是有「file」標籤的文章

[Bot Framework] How to reply an image

There are 2 ways to achieve that goal. First one, pass image url to channel if my source url is like http://abc.com/dog.png                var reply = context.MakeMessage();                                reply.Attachments.Add(new Attachment                 {                     ContentUrl = $" http://abc.com/dog.png ",                     ContentType = "image/png",                 }); Pass base64 encoded image data                 Stream fs = File.OpenRead("C:\\dog.png");                 byte[] img = fs.ToArray();        ...

[C#]UnauthorizedAccessException

當我們用 Directory .GetFiles()  在特定路徑下尋找檔案時, 若不幸程式存取到系統資料夾時(列如: System Volume Information), 則程式可能中斷並跳出 UnauthorizedAccessException 的錯誤訊息 避免的方式很簡單,   建議先不要找檔案,先找資料夾 Directory .GetDirectories( Path .GetDirectoryName(System.Reflection. Assembly .GetEntryAssembly().Location),   "*"   , SearchOption .TopDirectoryOnly); 過濾系統資料夾 if (d.Contains( "System Volume Information" )) continue ; if   ( new   FileInfo (d).Attributes ==   FileAttributes .System)   continue ; if   ( new   FileInfo (d).Attributes ==   FileAttributes .Hidden)   continue ; 再去尋訪剩下的資料夾, 並找出指定的檔案 ( SearchPattern  ) fls =   Directory .GetFiles(d,  SearchPattern ,   SearchOption .AllDirectories); 將結果合併成一個List 並輸出 if   (fls !=   null ) files = files.Concat(fls).ToList< string >(); 完整 Sample code 如下:                   ...

[Python] Upload files to FTP

Assume we'd like to upload files to FTP:\\ 192.168.1.12\ Download storage\EXE\ from ftplib import FTP def upload_file_ToFTP ( filename ) : print 'upload:' , filename ftp . storbinary ( 'STOR Download storage \ \ EXE \ \ ' + os . path . basename ( filename ) , open ( filename , 'rb' ) ) #Initialize the FTP setting ftp = FTP ( '192.168.1.12' ) ftp . login ( user = 'OOXX' , passwd = 'SCRETE' ) #get the current working directory cwd = os . getcwd ( ) #get all files from the current working folder files_list = os . listdir ( cwd ) #upload files and skip directories for fn in files_list : #get the full path file name _fn = os.path.realpath(fn) #Skip directories if os . path . isdir ( _fn ) : print 'Skip dir:' , _fn continue upload_file_ToFTP ( _fn ) #upload process completed, close FTP connection ftp . close ( )

[C++]How to append text to a file

Append  text to a  file See below procedure: open file,   CStdioFile::Open Set the file pointer to the end of the file. CFile::SeekToEnd write a text CStdioFile::WriteString For example: CStdioFile file; if (file.Open(L "C:\\Set.cmd" , CFile :: modeNoTruncate | CFile :: modeWrite ))      file. SeekToEnd () ;                                                file.WriteString(_T( "Hello" )); else {        //show failed }

[C#] FTP download sample code

If you'd like DL file through  WebRequestMethods, maybe you could try below sample code Input: filePath = "ftp://100.251.237.125/update.xml" targetPath  = update.xml public bool DwonlaodFileFromFTP( string filePath, string targetPath, out string errorMessage)         {             // initialize                      FtpWebRequest request = ( FtpWebRequest ) WebRequest .Create(filePath);             request.Credentials = new NetworkCredential (_user, _password);             request.Proxy = null ;             request.Method = WebRequestMethods . Ftp .DownloadFile;             request.UsePassive = false ; ...

[C#] FtpWebRequest failed

[C#] FtpWebRequest fails  I try to list files using FtpWebRequest but  it fails with a WebException 'The underlying connection was closed: An unexpected error occurred on a receive.'             string ftpPath = "ftp://" + this ._ip;                          FtpWebRequest request = ( FtpWebRequest ) WebRequest .Create(ftpPath);             request.Credentials = new NetworkCredential (_user, _password);             request.Proxy = null ;             request.Method = WebRequestMethods . Ftp .ListDirectory;              FtpWebResponse response = ( FtpWebResponse )request.GetResponse();            ...

[C#] 如何讀取Excel 中的某個欄位

如果想從這份xls檔案裡取出Wild這本書的價格(Price) 1. 需要 -add reference NPOI.dll -   匯入NPOI.HSSF.UserModel , NPOI.SS.UserModel; using   NPOI.HSSF.UserModel; using   NPOI.SS.UserModel; 2. 開檔(假設檔案路徑是  C:\book1.xls  ) HSSFWorkbook   wookbook; string  filepath=@"C:\book1.xls"; FileStream   file =   new   FileStream   ( filepath ,   FileMode .Open,   FileAccess .Read); byte [] bytes =   new   byte [file.Length]; file.Read(bytes, 0, (   int )file.Length); MemoryStream   ms =   new   MemoryStream   (bytes); wookbook =   new   HSSFWorkbook (ms); 3. 以每一行(row)的第一個欄位來做搜索匹配   public     string   GetToolConfigCell( HSSFWorkbook   wookbook   , string   sheetName,   string   rowName,   string   columnName)    {        ...