我有一个Image类型列的sqlserver表,我使用这段代码从我的db中恢复它。
public static byte[] ObtenerArchivo(string IdArchivo,bool GuardarEnDisco)
{
byte[] archivo = null;
MyContext db = new MyContext();
Double Versiond = 1010;
archivo = db.Versiones.Where(x => x.IntIdArchivo == IdArchivo && x.IntIdVersion == Versiond).Select(x => x.BinFisico).First();
return archivo;
}现在,要使mi文件可读性,我需要转换它。此应用程序是从Visual FoxPro继承的,在从我的db检索文件之后,必须使用此函数转换它。
**VFP Sintax
STRCONV(lcImage, 6)
In VFP help it says:
Converts character expressions between single-byte, double-byte, UNICODE, and locale-specific representations.6的意思是:
6 Converts UNICODE (wide characters) to double-byte characters.现在我的问题是,我怎样才能在c#中实现同样的对话呢?
编辑1:如果我不能像@Hans‘.并且知道我已经存储了文本文件、图像,在SQL字段中存储了64个编码的文件。如何使用C#存储、检索和更新这些文件以管理这些文件?
发布于 2015-01-08 19:31:55
@HansPassant对他的惯用性很满意,但在我的例子中,采取一些特殊的条件可以将字符串从双字节转换为单字节。
1- VFP将文本文件转换为双字节,这意味着我的原始文件仅为文本单字节格式。
2-要解码我的文件,只需删除vfp添加的字节。
这是密码:
public async Task<string> GetStringAsync(string IdArchivo)
{
string FinalData = await Task.Factory.StartNew(() =>
{
string NData = string.Empty;
Byte[] BData = GetBinaryData(IdArchivo);
string SData = Encoding.UTF8.GetString(BData);
for (int i = 0; i < SData.Length; i++)
{
if (i > 0)
i++;
if (i <= SData.Length - 1)
NData += SData[i];
}
return NData;
});
return FinalData;
}
public Byte[] GetBinaryData()
{
// Just retrieve the file from my database
}此过程移除数组中的所有奇数字节,并如我所料返回我的字符串。是的,它不是那么快,但至少解决了我的问题。
https://stackoverflow.com/questions/27626889
复制相似问题