Print Page | Close Window

Upload Image

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2078
Printed Date: 08-Nov-2025 at 6:29am


Topic: Upload Image
Posted By: bala
Subject: Upload Image
Date Posted: 19-Aug-2010 at 12:49pm
Hi
I want to upload image using DevForce
How I can achevie this?
 
 
Thanks



Replies:
Posted By: ting
Date Posted: 20-Aug-2010 at 6:38pm
You can use a third party control that allows users to select an image, or you will have to implement functionality to browse the disk for the file.  Once you have the bits, you can assign the bits to the property of the entity and it will get saved to the database when you call SaveChanges().


Posted By: vinothvdp
Date Posted: 20-Aug-2010 at 10:33pm
Hi,

You can use below code to upload image to db using ideablade,

  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");
            }
        }


Regards,
Vinoth


Posted By: bala
Date Posted: 23-Aug-2010 at 5:35am
Hi

Are you using webservice for it?

I am not able to understand

  ImageUpload CurrentFile = bsFile.Current as ImageUpload;

Could you able to put light on it

thanks


Posted By: vinothvdp
Date Posted: 23-Aug-2010 at 5:43am
Hi Bala,

No, i am not using any third party tools.

"ImageUpload"  is name of the table which included into ideablade object mapper with the same name.

using bellow step i am getting current item of the binding source, 

ImageUpload CurrentFile = bsFile.Current as ImageUpload;

And update the property of image column

CurrentFile.File= content;

Regards,
Vintoh


Posted By: bala
Date Posted: 23-Aug-2010 at 6:07am
Hi Vinod

I did not undestand object mapper..

How you binding also not undestanding..
If possible can you pass code or step.

ImageUpload CurrentFile = bsFile.Current as ImageUpload;

This line making really terrible for me..

Thanks



Print Page | Close Window