Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="userFile"></param>
        /// <param name="isThumb"></param>
        private void WriteFile(UploadedFile userFile, bool isThumb)
        {
            // Verify Files Exists
            string fullFilePath = FileLoaderUtil.GetFileOnDisk(userFile, isThumb);

            if (System.IO.File.Exists(fullFilePath))
            {
                // Write File
                Response.WriteFile(fullFilePath);

                // Set Header
                string contentType = userFile[UploadedFile.FileType].ToString();
                Response.ContentType = contentType;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Displays thumbnail if one exists and property set to true, otherwise display file Label. Default to display generic "Upload File" image
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="tablePrimaryKey"></param>
        private void DisplayLink(string tableName, string tablePrimaryKey)
        {
            string _savePath = System.Configuration.ConfigurationSettings.AppSettings["FileUploadLocation"].ToString() + this.PrimaryKeyTable;

            _savePath = Page.ResolveUrl(_savePath);

            // Cheeck to see if files are uploaded for this record
            FilesDa da = new FilesDa();
            DataSet ds = da.GetRecordsByTableAndTablePK(this.PrimaryKeyTable, int.Parse(tablePrimaryKey));

            // If files are uploaded, show thumb for default
            if (ds.Tables[0].Rows.Count > 0)
            {
                string fileId        = ds.Tables[0].Rows[0][UploadedFile.FileId].ToString();
                string fileExtension = ds.Tables[0].Rows[0][UploadedFile.FileExtension].ToString();
                string fileLabel     = ds.Tables[0].Rows[0][UploadedFile.FileLabel].ToString();

                bool isFileAnImage = FileLoaderUtil.IsImage(fileExtension);

                // show thumbnail of image
                if (_showThumbNail == true && isFileAnImage)
                {
                    linkText.Visible  = false;
                    linkImage.Visible = true;
                    UploadedFile biz = new UploadedFile();
                    biz.Get(int.Parse(fileId));

                    linkImage.ImageUrl = "DocumentLoader.aspx?fileId=" + Security.CustomCryptoHelper.Encrypt(fileId) + "&thumb=true";
                    linkImage.Attributes.Add("style", "border: solid 1px #cccccc; cursor: pointer;");
                    linkImage.ToolTip = "Click to view or edit this image.";
                }
                // show file label as link
                else if (!string.IsNullOrEmpty(fileLabel))
                {
                    //link.InnerHtml = "View " + fileLabel;
                    linkText.Text     = "View " + fileLabel;
                    linkText.Visible  = true;
                    linkImage.Visible = false;
                    link.Attributes.Add("style", "cursor: pointer;");
                }
                // default to showing generic view file image
                else
                {
                    linkText.Visible   = false;
                    linkImage.Visible  = true;
                    linkImage.ImageUrl = "~/Images/ViewFile.gif";
                }
            }
            else if (!string.IsNullOrEmpty(_linkName))
            {
                //link.InnerHtml = _linkName;
                linkText.Text     = _linkName;
                linkText.Visible  = true;
                linkImage.Visible = false;
            }
            else
            {
                linkText.Visible   = false;
                linkImage.Visible  = true;
                linkImage.ImageUrl = "~/Images/UploadFile.gif";
            }

            // Register's function for setting thumb image on plugin
            Page.ClientScript.RegisterStartupScript(this.GetType(), "ImageReloader", "function setThumb(newSrc) {  var pluginTmb = document.getElementById('" + linkImage.ClientID + "'); if(pluginTmb) { pluginTmb.src = newSrc; } }", true);
        }