Xml 将base64转换为字符串时获取system.Byte[]

Xml 将base64转换为字符串时获取system.Byte[],xml,c#-4.0,base64,Xml,C# 4.0,Base64,在xml中有一个标记,其类型如下 <xs:restriction base="xs:base64Binary" /> 现在,当我从我的应用程序中读取xml文件时,除了这个附件之外,所有节点都被成功分配 分配附件标签的代码如下所示 string Attach = dataRow2["Attachment"].ToString() 我在Attach中得到的值是System.Byte[] 不是标记之间的字符串值 我遗漏了什么吗?请帮助从字符串转换为字节永远不会起作用。使用Encodin

在xml中有一个标记,其类型如下

<xs:restriction base="xs:base64Binary" />
现在,当我从我的应用程序中读取xml文件时,除了这个附件之外,所有节点都被成功分配

分配附件标签的代码如下所示

string Attach = dataRow2["Attachment"].ToString()
我在
Attach
中得到的值是
System.Byte[]
不是标记之间的字符串值


我遗漏了什么吗?请帮助

从字符串转换为字节永远不会起作用。使用Encoding.UTF8.GetBytes()。@jdweng it
string Attach=Encoding.UTF8.GetBytes(dataRow2[“Attachment”])
检查DataTable以查看它是否真的是一个字符串。DataTable单元格是可以包含任何类型的对象。使用这个:byte[]Attach=Encoding.UTF8.GetBytes(dataRow2[“Attachment”])。如果这不起作用,请根据需要更改编码类型UTF8。@jdweng
System.Text.encoding.GetBytes(char[])在im使用
byte[]Attach=encoding.UTF8.GetBytes(dataRow2[“Attachment”])
时有一些无效的参数。检查您拥有的数据类型。您可以使用以下内容:string cellType=dataRow2[“附件”].GetType().ToString();从字符串到字节的转换是行不通的。使用Encoding.UTF8.GetBytes()。@jdweng it
string Attach=Encoding.UTF8.GetBytes(dataRow2[“Attachment”])
检查DataTable以查看它是否真的是一个字符串。DataTable单元格是可以包含任何类型的对象。使用这个:byte[]Attach=Encoding.UTF8.GetBytes(dataRow2[“Attachment”])。如果这不起作用,请根据需要更改编码类型UTF8。@jdweng
System.Text.encoding.GetBytes(char[])在im使用
byte[]Attach=encoding.UTF8.GetBytes(dataRow2[“Attachment”])
时有一些无效的参数。检查您拥有的数据类型。您可以使用以下内容:string cellType=dataRow2[“附件”].GetType().ToString();
string Attach = dataRow2["Attachment"].ToString()