读取数据库大文本和大二进制数据
byte[] LoadImageFile(
string fileName,
string fileLocation,
int maxImageSize
)
{
byte[] imagebytes = null;
string fullpath = fileLocation + fileName;
Console.WriteLine("Loading File:");
Console.WriteLine(fullpath);
FileStream fs = new FileStream(fullpath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
imagebytes = br.ReadBytes(maxImageSize);
Console.WriteLine(
"Imagebytes has length {0} bytes.",
imagebytes.GetLength(0)
);
return imagebytes;
}
string GetTextFile(string textFile)
{
string textBytes = null;
Console.WriteLine("Loading File: " + textFile);
FileStream fs = new FileStream(textFile, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
textBytes = sr.ReadToEnd();
public Bitmap GetImage()
{
MemoryStream ms = new MemoryStream(imageBytes);
Bitmap bmap = new Bitmap(ms);
return bmap;
}
Console.WriteLine("TextBytes has length {0} bytes.",
textBytes.Length);
return textBytes;
}
void ExecuteInsertImages(int imageFileNumber)
{
string imageFileName = null;
byte[] imageImageData = null;
imageFileName =
imageFilePrefix + imageFileNumber.ToString() + imageFileType;
imageImageData =
LoadImageFile(imageFileName, imageFileLocation, maxImageSize);
cmd.Parameters["@imagefile"].Value = imageFileName;
cmd.Parameters["@imagedata"].Value = imageImageData;
ExecuteCommand(cmd.CommandText);
}
string GetTextFile(string textFile)
{
string textBytes = null;
Console.WriteLine("Loading File: " + textFile);
FileStream fs = new FileStream(textFile, FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
textBytes = sr.ReadToEnd();
Console.WriteLine("TextBytes has length {0} bytes.",
textBytes.Length);
return textBytes;
}
public bool GetRow()
{
long textSize;
int bufferSize = 100;
long charsRead;
textChars = new Char[bufferSize];
if (dr.Read())
{
// Get file name
textFile = dr.GetString(0);
Console.WriteLine("------ start of file:");
Console.WriteLine(textFile);
textSize = dr.GetChars(1, 0, null, 0, 0);
Console.WriteLine("--- size of text: {0} characters -----",
textSize);
Console.WriteLine("--- first 100 characters in text -----");
charsRead = dr.GetChars(1, 0, textChars, 0, 100);
Console.WriteLine(new String(textChars));
Console.WriteLine("--- last 100 characters in text -----");
charsRead = dr.GetChars(1, textSize - 100, textChars, 0, 100);
Console.WriteLine(new String(textChars));
return true;
}
else
{
return false;
}
}
浙公网安备 33010602011771号