开发者

How to convert XDocument to FileStream in C#

开发者 https://www.devze.com 2023-04-13 06:55 出处:网络
I have seen this post How to correctly open a FileStream for usage with an X开发者_运维知识库Document but it doesn\'t help me since I don\'t have the path to the file on the local hard drive. This XDo

I have seen this post How to correctly open a FileStream for usage with an X开发者_运维知识库Document but it doesn't help me since I don't have the path to the file on the local hard drive. This XDocument is getting passed to another computer so the BaseURI is worthless.

I want to know how to convert an XDocument into a FileStream without using a local file path.


A FileStream is used to write directly to a file, so if you don't have a file path, you don't have a FileStream.

You can, however, write to other streams, like a MemoryStream:

using (var stream = new MemoryStream())
{
    yourDocument.Save(stream);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号