Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to convert from null to byte array?
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
How to convert from null to byte array?
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01337009
Message ID:
01337009
Vues:
55
Hi everybody,

I need to convert null to byte array. I have a property that corresponds to varbinary(max) in my database.

Here is the get definition
[Bindable(true, BindingDirection.TwoWay), Category("User-Defined"), Description("Default Picture")]
public byte[] DefaultPicture
{
    get
    {
       // We need to convert picture to byte array 
        Byte[] imgByte = null;
        try
        {

            if (this.myPic.HasFile && this.myPic.PostedFile != null)
            {
                if (this.myPic.FileBytes.Length > 10240) // exception case
                    throw new Exception("Image File was is too big: " +
                            (this.myPic.FileBytes.Length / 1024).ToString() + " kB.");
                else
                    imgByte = this.myPic.FileBytes;
            }
        }
        catch (Exception e)
        {
            throw (e);
            //exception handled
        }
         
       return imgByte ;
    }
The parameter is declared in ASPX page as type = "Byte"

I found that I'm getting an error if I don't select an image.

What should I do?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform