Exemple #1
0
        // ファイル転送 strSubPathは付加するフォルダ名
        public static void sendFile(Network network, String strFileName, String strFullPath, String strSubPath)
        {
            try
            {
                MemoryStream memory = new MemoryStream();
                bool bWrite = false;
                using (System.IO.FileStream win = new System.IO.FileStream(strFullPath, FileMode.Open, FileAccess.Read))
                {
                    System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(memory, System.IO.Compression.CompressionMode.Compress);
            //                    System.IO.Compression.DeflateStream gzip = new System.IO.Compression.DeflateStream(memory, System.IO.Compression.CompressionMode.Compress);
                    byte[] buffer = new byte[1024 * 1024 * 50];
                    while (true)
                    {
                        int nReadSize = win.Read(buffer, 0, buffer.Length);
                        if (nReadSize == 0)
                            break;
                        bWrite = true;
                        gzip.Write(buffer, 0, nReadSize);
            //                        memory.Write(buffer, 0, nReadSize);
                    }
                    gzip.Close();
                }

                if (bWrite)
                {
                    network.sendByte(1);
                    String strTransferPath = Path.Combine(strSubPath, strFileName);
                    network.sendString(strTransferPath);

                    byte[] data = memory.ToArray();
                    network.sendBinary(data);
                }

                memory.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            //                MessageBox.Show(ex.Message);
            }
        }