This is a migrated thread and some comments may be shown as answers.

Attachment directory path

7 Answers 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 29 Aug 2013, 03:17 PM
Hi,
I am using the attachment feature in a radGrid and it is working but I have no idea on where the attchment get saved and how I can define the folder path to save the files. I do not like them into the database but in a dedicated directory.



7 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 30 Aug 2013, 06:34 AM
Hi Felice,

I guess you are using a GridAttachmentColumn and you don't want to save the file to db.One method to do this is that you can access the attachment column as a RadUpload in the edit or insert mode and specify the target folder you want to save the file.PLease try the following code snippet.

ASPX:
<telerik:GridAttachmentColumn  HeaderText="AttachmentColumn" UniqueName="AttachmentColumn" AttachmentDataField="BinaryData">
</telerik:GridAttachmentColumn>

C#:
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
   {
     GridEditableItem edititem = (GridEditableItem)e.Item;
     RadUpload upload = (edititem.EditManager.GetColumnEditor("AttachmentColumn") as GridAttachmentColumnEditor).RadUploadControl;
     upload.TargetFolder = "TargetFolder"; //Specify the folder path you want to save the file
    }

Thanks,
Princy
0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Aug 2013, 06:39 AM
Hello,

Please try with the below code snippet.

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item.IsInEditMode && e.Item is GridEditableItem)
       {
           GridEditableItem item = e.Item as GridEditableItem;
           (item["AttachmentColumn"].Controls[0] as RadUpload).TargetFolder = "YourTargetFolderPath/NameHere"; //Set your target filepath here
       }
   }

<telerik:GridAttachmentColumn                    UniqueName="AttachmentColumn">
                </telerik:GridAttachmentColumn>

Thanks,
Jayesh Goyani
0
Felice
Top achievements
Rank 1
answered on 30 Aug 2013, 07:54 AM
Thanks a lot for your support but it is still not working. I am trying to save for test purpose to the desktop folder but does not work and I do not get errors.

<telerik:GridAttachmentColumn AllowedFileExtensions="jpeg,jpg,pdf,doc,tiff,png" ButtonType="PushButton" FileName="attachment" FilterControlAltText="Filter column column" HeaderText="Carica file" UniqueName="column">

using Telerik.Web.UI;
 
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode && e.Item is GridEditableItem)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                (item["AttachmentColumn"].Controls[0] as RadUpload).TargetFolder = @"c:\users\pink\desktop\"; //Set your target filepath here
            }
        }


0
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Aug 2013, 08:23 AM
Hello,

Please try with the below code snippet.
Please create one folder in your root directory and try this folder name.



You have assigned physical path, but a virtual path was expected.

Thanks,
Jayesh Goyani
0
Felice
Top achievements
Rank 1
answered on 30 Aug 2013, 09:08 AM
Dear Jayesh,
thanks a lot for your support. I tried but it doesn' t work. I do not have a temp folder in my solution but I created an "attachments" folder and pointed to it. It does not work. I am going mad with this!  The solution files are here. Your support is really appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
 
 
 
namespace WebApplication4
{
    public partial class CasaFirenze : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
 
        protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item.IsInEditMode && e.Item is GridEditableItem)
            {
                GridEditableItem item = e.Item as GridEditableItem;
                (item["AttachmentColumn"].Controls[0] as RadUpload).TargetFolder = "attachments"; //Set your target filepath here
                //(item["AttachmentColumn"].Controls[0] as RadUpload).TargetFolder = @"c:\users\pink\desktop/foto.jpeg"; //Set your target filepath here
            }
        }
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 30 Aug 2013, 10:05 AM
Hello,

Please update below code snippet in your code.

1. changed UniqueName
<telerik:GridAttachmentColumn AllowedFileExtensions="jpeg,jpg,pdf,doc,tiff,png" ButtonType="PushButton" FileName="attachment" FilterControlAltText="Filter column column" HeaderText="Carica file" UniqueName="AttachmentColumn">
               </telerik:GridAttachmentColumn>

2. Added ItemDataBound event
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" AllowSorting="True" CellSpacing="0" Culture="it-IT" DataSourceID="SqlDataSource1" GridLines="None" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="True"
       OnItemDataBound="RadGrid1_ItemDataBound">



Thanks,
Jayesh Goyani
0
Felice
Top achievements
Rank 1
answered on 30 Aug 2013, 11:52 AM
Thanks a lot. It works now.

Tags
Grid
Asked by
Felice
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Felice
Top achievements
Rank 1
Share this question
or