如果将DirectoryInfo实例从PC1发送到PC2,GetFiles或GetDirectories是否仍在起作用?
public void DirTest()
{
//On first PC:
DirectoryInfo driveC = new DirectoryInfo(@"C:\randomdir\");
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ns = new MemoryStream();
bf.Serialize(ns, driveC);
SendStream(ns); //Sending the stream to the second PC
//On second PC:
ns = ReceiveStream(); //Receiving the stream from the first PC
ns.Position = 0;
DirectoryInfo di = (DirectoryInfo)bf.Deserialize(ns);
//Does this work?
foreach (FileInfo item in di.GetFiles())
{
Debug.WriteLine(item);
}
}
如果您在同一台PC上执行该代码,则可以工作,但是我没有环境来测试这是否可以在2台不同的PC上工作。
也许子目录和文件保存在directoryinfo类的数组中,因为我发现了此序列化函数:
相关分类