Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
THIS IS THE CODE BEHIND THE GRIDVIEW

C#
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            
            switch (e.Row.RowType)
            {
               case DataControlRowType.DataRow:
                    FileSave fs = (FileSave)e.Row.DataItem;
                       switch (fs.contentType.ToLower())
                       {
                            case "image/pjpeg":
                            case "image/gif":
                            case "application/msword":
                            case "text/plain":
                                break;
                            default:
                                break;
                        }
                    HyperLink myLink = (HyperLink)e.Row.FindControl("lnkView");
            myLink.Enabled = true;
                       break;
                    }
            }

THIS IS THE CODE THAT'S GIVING ME AN ERROR

 public partial class DownloadFile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString.Get("ID") != null)
            {
                Response.Clear(); 
                 HERE IS THE ERROR                                                                        Guid ID = new Guid(Request.QueryString.Get("ID"));
                BLL.FileSave myFile = new BLL.FileSave();
                Response.ContentType = "application/x-uknown";
                Response.AppendHeader("Content_Disposition", "attachment; fileName=\"");
                if (myFile.containsFile)
                {
                    Response.BinaryWrite(myFile.fileData);
                }
                else
                {
                    Response.Redirect("~/");
                }

            }
        }
    }
}



Update
This is the code in the class
and the ID is an int in the database and the businesslogic class calles FileSave


public static FileSave GetItem(Guid ID)
        {
            FileSave myFile = null;
            csDAL objdal = new csDAL();
            IDataReader dr;
            dr = null;
            List<csParameterListType> objpar = new List<csParameterListType>();
            objpar.Add(new csParameterListType("@ID", SqlDbType.Int, ID));
            if (dr.Read())
            {
                myFile = new FileSave(dr);
            }
            dr.Close();
            return myFile ;
        }
Posted
Updated 11-Sep-11 7:03am
v3

1 solution

You should tell us what the value of Request.QueryString.Get("ID") is.
From the exception it seems clear that Request.QueryString.Get("ID") does not represent a valid GUID



Ok you cannot convert an int to a GUID, I'm not sure you know what it actually is so give this wiki entry a read Globally unique identifier[^].

That said if you just remove the line Guid ID = new Guid(Request.QueryString.Get("ID")); then your code should work as you don't even use the variable ID. GetItem takes a Guid but now you're trying to convert the Guid to an integer (objpar.Add(new csParameterListType("@ID", SqlDbType.Int, ID));) so forget about Guid and just use int
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900