public ObservableCollection <FileAndDirAttributes> PopulateDataGrid(string path) { FileProperties file; ObservableCollection <FileAndDirAttributes> FileList = new ObservableCollection <FileAndDirAttributes>(); FileList.Add(new FileAndDirAttributes { Type = true, FileName = "Up", FileIcon = "/Resources/Icons/back.png", FileDirectory = GetParent(path) }); // Get directories from the path string[] dirs = Directory.GetDirectories(@path, "*", SearchOption.TopDirectoryOnly); foreach (string dir in dirs) { FileList.Add(new FileAndDirAttributes { Type = true, FileIcon = "/Resources/Icons/folder.png", FileName = Path.GetFileName(dir), FileDirectory = dir }); } // Get files from the path string[] files = Directory.GetFiles(@path, "*", SearchOption.TopDirectoryOnly); foreach (string f in files) { file = new FileProperties(f); FileList.Add(new FileAndDirAttributes { Type = false, FileIcon = "/Resources/Icons/file.png", FileName = file.GetFileName(), FileSize = file.GetFileSize(), FileDirectory = file.GetDirectory(), FileCreated = file.GetFileCreated(), FileAccessed = file.GetFileLastAccess(), FileModified = file.GetFileLastModify() }); } return(FileList); }
public void SendFile(string FileDir, string IP) { clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); byte[] m_clientData; FileProperties file = new FileProperties(FileDir); byte[] fileName = Encoding.UTF8.GetBytes(file.GetFileName()); //file name byte[] fileData = File.ReadAllBytes(FileDir); //file byte[] fileNameLen = BitConverter.GetBytes(fileName.Length); //lenght of file name m_clientData = new byte[4 + fileName.Length + fileData.Length]; fileNameLen.CopyTo(m_clientData, 0); fileName.CopyTo(m_clientData, 4); fileData.CopyTo(m_clientData, 4 + fileName.Length); try { clientSock.Connect(IP, 9050); //target machine's ip address and the port number if (IsSocketConnected(clientSock)) { clientSock.Send(m_clientData); Console.WriteLine("Shit Connected!"); } else { Console.WriteLine("Shit Not Connected!"); } clientSock.Close(); } catch (SocketException ex) { if (ex.NativeErrorCode.Equals(10035)) { Console.WriteLine("Still Connected, but the Send would block"); } else { string msg = "Unable to connect with partner. Error code " + ex.NativeErrorCode + "!"; Console.WriteLine(msg); } } }