コード例 #1
0
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string        sRoot = System.Configuration.ConfigurationManager.AppSettings["DocumentsRoot"];
        StringBuilder sb    = new StringBuilder();

        if (fuFile.HasFile)
        {
            using (WACDataClassesDataContext wDataContext = new WACDataClassesDataContext())
            {
                string s     = null;
                int?   i     = null;
                int    iCode = 0;
                try
                {
                    int?iPK_Level_03 = null;
                    if (ddlSpecialLevel3.Visible == true)
                    {
                        iPK_Level_03 = Convert.ToInt32(ddlSpecialLevel3.SelectedValue);
                    }

                    string sWACForm = null;
                    if (!string.IsNullOrEmpty(ddlWACForm.SelectedValue))
                    {
                        sWACForm = ddlWACForm.SelectedValue;
                    }

                    iCode = wDataContext.documentArchive_add(fuFile.FileName, ddlAreaSectorFolder.SelectedValue, iPK_Level_01, iPK_Level_02, iPK_Level_03, sWACForm, cal.SelectedDate, Session["userName"].ToString(), ref s, ref i);

                    if (iCode == 0)
                    {
                        fuFile.SaveAs(sRoot + StrArea + @"\" + s);

                        sb.Append("File Successfully Uploaded");
                        sb.Append("<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;File Name: " + fuFile.FileName + " >> " + s);
                        sb.Append("<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content Type: " + fuFile.PostedFile.ContentType);
                        sb.Append("<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Content Length: " + fuFile.PostedFile.ContentLength);
                        lblMessage.Text = sb.ToString();

                        btnCloseWindow.Visible = true;
                    }
                    else
                    {
                        WACAlert.Show("Error returned from database.", iCode);
                    }
                }
                catch (Exception ex)
                {
                    try
                    {
                        int iCode2 = 0;
                        iCode2 = wDataContext.documentArchive_delete(i, Session["userName"].ToString());
                        if (iCode2 != 0)
                        {
                            WACAlert.Show("Error returned from database.", iCode2);
                        }
                        lblMessage.Text = "Error Uploading File: " + ex.Message;
                    }
                    catch (Exception ex2) { lblMessage.Text = "Error Uploading File: " + ex2.Message; }
                }
            }
        }
        else
        {
            lblMessage.Text = "You must select a file to upload.";
        }
    }