简体   繁体   English

使用C#从BLOB Oracle下载文件

[英]Download File from BLOB Oracle using c#

i have created simple project in c# to save file data into Oracle Database using BLOB data type and it worked. 我已经在c#中创建了一个简单项目,使用BLOB数据类型将文件数据保存到Oracle数据库中,并且它可以正常工作。 i used devexpress gridcontrol to show the data. 我用devexpress gridcontrol来显示数据。 This is the sample data that i have created. 这是我创建的示例数据。

在此处输入图片说明

in the btnDownload will download data from blob oracle that i selected row. btnDownload中,将从我选择的行的blob oracle下载数据。 here is my code: 这是我的代码:

var rowHandle = gridView1.FocusedRowHandle;
var obj = gridView1.GetRowCellValue(rowHandle, "FILENAME");

if(koneksidb.con.State == ConnectionState.Open)
{
    koneksidb.con.Close();
}
koneksidb.con.Open();
OracleCommand cmd = new OracleCommand();
OracleDataReader dr;
cmd.CommandText = @"SELECT * FROM LATIHANFILEMANAGER WHERE FILENAME='"+ obj +"'";
cmd.Connection = koneksidb.con;
dr = cmd.ExecuteReader();
while(dr.Read())
{
    UInt32 FileSize = Convert.ToUInt32(dr.GetInt32(dr.GetOrdinal("FILESIZE"))); //get file size from table LATIHANFILEMANAGER
    rawData = new byte[FileSize];
    var nilai = dr.GetBytes(dr.GetOrdinal("FILEDATA"), 0, rawData, 0, (int)FileSize); //this file that i wanna download
    FileStream fls = new FileStream(@"D:\newfile.png", FileMode.OpenOrCreate, FileAccess.Write);
    fls.Write(rawData, 0, (int)FileSize);
    fls.Close();
}
dr.Close();

when i run this project and download the image, i got a file and file size but it cannot be opened. 当我运行该项目并下载图像时,我得到了文件和文件大小,但无法打开。

here is the file that i captured: 这是我捕获的文件:

在此处输入图片说明

this tutorial i got from this link: https://docs.oracle.com/cd/E17952_01/connector-net-en/connector-net-programming-blob-reading.html 我从以下链接获得了本教程: https : //docs.oracle.com/cd/E17952_01/connector-net-en/connector-net-programming-blob-reading.html

any suggest? 有什么建议吗?

first, you show your Image(BLOB) from database to PictureBox, than use SaveFileDialog. 首先,将您的Image(BLOB)从数据库显示到PictureBox,然后使用SaveFileDialog。 for more information visit How to use saveFileDialog for saving images in C#? 有关更多信息,请访问如何使用saveFileDialog在C#中保存图像?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 下载 Blob 文件到 Memory Stream 从 Azure 使用 ZD7EFA19FBE74D3972FDZ5ADB6D - Download Blob file into Memory Stream from Azure using C# 使用c#asp.net从sql下载blob文件,并且不会在其相关查看器应用程序中显示? - download blob file from sql using c# asp.net and do not displaying in their related viewer applications? 使用c#asp.net从sql下载blob文件,并向用户显示保存对话框 - download blob file from sql using c# asp.net and present a save dialog to user 使用 ODP .NET 使用 C# 从 Oracle 数据库读取 BLOB - Reading a BLOB from Oracle Database with C# using ODP .NET 使用 C# 从 blob 数据 Oracle 播放视频 - Play video from blob data Oracle using C# 使用C#下载Blob文件时找不到本地文件路径 - Local file path not found while download blob file using c# 如何使用 c# 从 Azure 中删除 blob 不可变文件 - How to delete blob immutable file from Azure using c# C#:从 ADLS gen2 blob 下载大型 json 文件并反序列化为对象 - C#: Download large sized json file from ADLS gen2 blob and Deserialize to object 如何使用C#从Azure容器/ Blob中读取/下载所有文件? - How to read/Download all files from a Azure container/Blob using C#? 如何使用 c# 从 Azure Blob 存储的单个请求中下载多个文件? - How to download multiple files in a single request from Azure Blob Storage using c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM