New Posts New Posts RSS Feed: Upload file into Database
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Forum LockedUpload file into Database

 Post Reply Post Reply
Author
vinothvdp View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Sep-2007
Location: India
Posts: 27
Post Options Post Options   Quote vinothvdp Quote  Post ReplyReply Direct Link To This Post Topic: Upload file into Database
    Posted: 28-Feb-2009 at 9:09pm

Hi sir,

I am using SQL server 2005, how to store and retrieve. Xls,. Doc,. PDF,. jpg ,.bmp file into database, can you give some me examples.

 
Thank you,
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 03-Mar-2009 at 8:41am
This would appear to be  a SQL Server issue involving storing and retrieving of data, not an IdeaBlade issue involving storing amd retrieving of Business Entities.
Back to Top
vinothvdp View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Sep-2007
Location: India
Posts: 27
Post Options Post Options   Quote vinothvdp Quote  Post ReplyReply Direct Link To This Post Posted: 03-Mar-2009 at 9:48pm
i tried this,this working fine,is this right?

PersistenceManager PM = PersistenceManager.DefaultManager;

EntityList<ImageUpload> ListDatas = new EntityList<ImageUpload>();

private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)

{

ListDatas.Add(ImageUpload.Create(PM));

bsFile.MoveLast();

}

private void Form1_Load(object sender, EventArgs e)

{

ListDatas.ReplaceRange(PM.GetEntities<ImageUpload>());

bsFile.DataSource = ListDatas;

}

OpenFileDialog openFileDialog1 = new OpenFileDialog();

private void SelectFileultraButton_Click(object sender, EventArgs e)

{

openFileDialog1.Filter = "All Files (*.*)|*.*";

openFileDialog1.Title = "Select File";

if (DialogResult.Cancel == openFileDialog1.ShowDialog())

{

return;

}

fileNameUltraTextEditor.Text = openFileDialog1.FileName;

string fileName = Path.GetFileName(fileNameUltraTextEditor.Text.ToString());

byte[] content = ReadFileToByteArray(fileName);

ImageUpload CurrentFile = bsFile.Current as ImageUpload;

CurrentFile.File= content;

CurrentFile.FileName = fileName;

}

protected static byte[] ReadFileToByteArray(string fileName)

{

FileStream fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read);

long len;

len = fileStream.Length;

Byte[] fileAsByte = new Byte[len];

fileStream.Read(fileAsByte, 0, fileAsByte.Length);

MemoryStream memoryStream = new MemoryStream(fileAsByte);

return memoryStream.ToArray();

}

private void saveToolStripButton_Click(object sender, EventArgs e)

{

if (PM.HasChanges())

{

try

{

PM.SaveChanges();

MessageBox.Show("Sucessfully saved");

}

catch (Exception ex)

{

MessageBox.Show(ex.Message.ToString());

}

}

else

{

MessageBox.Show("Nothing to save");

}

}

private void RetriveultraButton_Click(object sender, EventArgs e)

{

string fileName = string.Empty;

byte[] content = null;

ImageUpload CurrentFile = bsFile.Current as ImageUpload;

fileName = CurrentFile.FileName;

content = CurrentFile.File;

DirectoryInfo di = new DirectoryInfo("C:\\Test");

if (di.Exists == false)

{

di.Create();

}

FileStream fs = new FileStream(di + "\\" + fileName, FileMode.Create);

fs.Write(content, 0, System.Convert.ToInt32(content.Length));

fs.Seek(0, SeekOrigin.Begin);

fs.Close();

}

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down