This question is locked. New answers and comments are not allowed.
hi, i am more and more getting in love testing your product and i am thinking seriously to move all my work in the future to depend on your control .
i am having this scenario
i want to have a gird with articles dta source where the article db will have an image
now what i want to know how to do is
- how can i save the name of the uploaded image in the image field in DB
- if the user uploads a file that don't have the same name of the one already in DB how can i delete that and upload the new file and update the Image DB filed name with it ?
thx in advanced.
i am having this scenario
i want to have a gird with articles dta source where the article db will have an image
now what i want to know how to do is
- how can i save the name of the uploaded image in the image field in DB
- if the user uploads a file that don't have the same name of the one already in DB how can i delete that and upload the new file and update the Image DB filed name with it ?
thx in advanced.
11 Answers, 1 is accepted
0
Hello feras,
You can check this online example. Have in mind it is using the SessionDataSource control which does not persist the changes in the database for example purpose.
All the best,
Albert
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
You can check this online example. Have in mind it is using the SessionDataSource control which does not persist the changes in the database for example purpose.
All the best,
Albert
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
feras
Top achievements
Rank 1
answered on 18 Nov 2008, 12:59 AM
hi,
thanks for the reply,
but still this example does not answer my question as i am using sql data source and automatic operations.
if you reread my question you would see that i want the db field to be inserted or updated with the image name being uploaded ,
plus i want to compare new file upload with old one if the name is not the same i want the old one to be removed from hard disk and replaced with the new one.
plus as i am reading the manual there is suppose to be auto saving of file how does htis work in my requirement ?
please this is urgent, and i am going to buy telerk full suite today.
thanks for the reply,
but still this example does not answer my question as i am using sql data source and automatic operations.
if you reread my question you would see that i want the db field to be inserted or updated with the image name being uploaded ,
plus i want to compare new file upload with old one if the name is not the same i want the old one to be removed from hard disk and replaced with the new one.
plus as i am reading the manual there is suppose to be auto saving of file how does htis work in my requirement ?
please this is urgent, and i am going to buy telerk full suite today.
0
Hello feras,
RadUpload does not support automatic uploads in databases. This example is the closest we got to your scenario so you can use it as a start.
Regards,
Albert
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
RadUpload does not support automatic uploads in databases. This example is the closest we got to your scenario so you can use it as a start.
Regards,
Albert
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
feras
Top achievements
Rank 1
answered on 19 Nov 2008, 10:28 AM
ok,
you know what, i am really disappointed, with this short none elaborating answer.
first for me it is misleading that it is not mentioned anywhere that you cant do automatic operation with radupload and grid.
second that example bare bone and does not answer my questions
third the other part of my question was not answered which is how to retrieve the name of the uploaded file and compare it with already uploaded one, and if it is not the same delete the old one and update the image filed name in DB, but if it is the same just overwrite the file and update the image filed name .
now as i understood saving the file part is done automatically through setting target directory.
i really hate to say it as i really see you have great set of products, but is this the premium support ?
thx in advanced for listening
you know what, i am really disappointed, with this short none elaborating answer.
first for me it is misleading that it is not mentioned anywhere that you cant do automatic operation with radupload and grid.
second that example bare bone and does not answer my questions
third the other part of my question was not answered which is how to retrieve the name of the uploaded file and compare it with already uploaded one, and if it is not the same delete the old one and update the image filed name in DB, but if it is the same just overwrite the file and update the image filed name .
now as i understood saving the file part is done automatically through setting target directory.
i really hate to say it as i really see you have great set of products, but is this the premium support ?
thx in advanced for listening
0
Hello feras,
I am sorry for your frustration.
Please note that these are public forums where you can get a help from the community, but there is no guarantee that a Telerik member will respond (although we do that in 99% of the cases). You can use the support ticketing system to get a faster response from Telerik Support.
Now, onto the questions - here is what you can do
1. Do not use TargetFolder or TargetPhysicalFolder because in this way the files are saved to the file system automatically. You need to save the file manually. This will give you an access to the uploaded file's properties like name, extension, contentlength, etc.
2. Having the name of the uploaded file - you can query the database and compare it with the value in the database. If they are different - you can use the .NET framework classes to delete the old file from the disk. Then you can update the database with the new name.
I hope that helps.
Greetings,
Veselin Vasilev
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I am sorry for your frustration.
Please note that these are public forums where you can get a help from the community, but there is no guarantee that a Telerik member will respond (although we do that in 99% of the cases). You can use the support ticketing system to get a faster response from Telerik Support.
Now, onto the questions - here is what you can do
1. Do not use TargetFolder or TargetPhysicalFolder because in this way the files are saved to the file system automatically. You need to save the file manually. This will give you an access to the uploaded file's properties like name, extension, contentlength, etc.
2. Having the name of the uploaded file - you can query the database and compare it with the value in the database. If they are different - you can use the .NET framework classes to delete the old file from the disk. Then you can update the database with the new name.
I hope that helps.
Greetings,
Veselin Vasilev
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Arni
Top achievements
Rank 1
answered on 03 Dec 2008, 07:32 AM
int counter = 1; |
//string date = DateTime.Now.ToString("dd_MM_yyy_hh_mm"); |
if (RadUpload1.UploadedFiles.Count > 0) |
{ |
foreach (Telerik.Web.UI.UploadedFile file in RadUpload1.UploadedFiles) |
{ |
AttachmentsEN loAtten = new AttachmentsEN(); |
Attachment loAttbs = new Attachment(); |
int i = 0; |
bool recaff = new bool(); |
loAtten.TaskID = Convert.ToInt32(ddlTaskID.SelectedValue); |
string targetFolder = Server.MapPath(RadUpload1.TargetFolder); |
string targetFileName = System.IO.Path.Combine(targetFolder, |
file.GetNameWithoutExtension() + Counter.ToString()+ file.GetExtension()); |
while (System.IO.File.Exists(targetFileName)) //.(Used to compare the old file and New File) |
{ |
counter++; |
targetFileName = System.IO.Path.Combine(targetFolder, |
file.GetNameWithoutExtension() + Counter.ToString+ file.GetExtension()); |
} |
loAtten.PhysicalFileName = file.FileName; |
file.SaveAs(targetFileName); |
loAtten.ActualFileName = targetFileName; |
loAtten.TypeCategory = file.GetExtension(); |
loAtten.Path = targetFolder.ToString(); |
try |
{ |
recaff = loAttbs.Insert(loAtten); |
ErrorDescription = ("Records added Successfully"); |
lblMesg.Text = ErrorDescription; |
} |
catch (Exception ex) |
{ |
lblMesg.Visible = true; |
lblMesg.Text = ex.Message.ToString(); |
} |
} |
I have given Code Example How if same named file uploaded .. asign variable int counter =1.(Used to compare the old file and New File)
check each uploadingg file if file already exist it add one in counter so tht tht file is saved as file1.doc..im the target folder. and saved as the same way in db...
THis I hv done for Inserting..even if its is the image file it wil saved to the db..U rimage url field in db shd be nvarchar(max).so tht it stores the path.. regarding updating I am under process after I hv done I wil reply U.
Thank u.
0
feras
Top achievements
Rank 1
answered on 04 Dec 2008, 01:05 AM
thanks alot man for the code,
i will try it out :)
i will try it out :)
0
Arni
Top achievements
Rank 1
answered on 04 Dec 2008, 04:38 AM
The above code has small mistake.
that is.. once u set targetfolder in properties ..
It is storing the file first b4 going ito the loop and again the same file with the given name.. so twicely storing..
do not set target folder b4 loop or in properties.
put radupload1.targetfolder="~/files"; after the loop.
rest for updating is also the same code. and regarding deleting the record is also the simple asusual.U can try easily
that is.. once u set targetfolder in properties ..
It is storing the file first b4 going ito the loop and again the same file with the given name.. so twicely storing..
do not set target folder b4 loop or in properties.
put radupload1.targetfolder="~/files"; after the loop.
rest for updating is also the same code. and regarding deleting the record is also the simple asusual.U can try easily
0
feras
Top achievements
Rank 1
answered on 04 Dec 2008, 09:10 AM
thanks alot man for the heads up and your efforts :)
0
Ramkumar
Top achievements
Rank 1
answered on 29 Nov 2013, 04:59 AM
Hi Shinu,
I tried with the gridattachment column but can't able to insert a data into a grid i am attaching file pls review it and make you suggesions
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RadgridAttachment.Default" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html>
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
<
telerik:RadCodeBlock
ID
=
"codeblock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function ClientFileSelected(sender, args) {
var filePath = sender.getFileInputs()[0].value;
var fileName = filePath.substring(filePath.lastIndexOf("\\") + 1);
//Access your file name here
var fileinputs = sender.getFileInputs();
for (var i = fileinputs.length - 1; i >= 0; i--) {
sender.clearFileInputAt(i);
}
}
</
script
>
</
telerik:RadCodeBlock
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
div
>
<
asp:ScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
></
asp:ScriptManager
>
<
telerik:RadAjaxPanel
ID
=
"RadAjaxPanel1"
runat
=
"server"
Height
=
"200px"
Width
=
"300px"
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AutoGenerateColumns
=
"false"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnUpdateCommand
=
"RadGrid1_UpdateCommand"
>
<
MasterTableView
CommandItemDisplay
=
"Top"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"ID"
UniqueName
=
"ID"
HeaderText
=
"ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridAttachmentColumn
UniqueName
=
"Attachment"
HeaderText
=
"Attachment"
UploadControlType
=
"RadAsyncUpload"
>
</
telerik:GridAttachmentColumn
>
<
telerik:GridEditCommandColumn
>
</
telerik:GridEditCommandColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
</
telerik:RadAjaxPanel
>
</
div
>
</
form
>
</
body
>
</
html
>
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
RadgridAttachment
{
public
partial
class
Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
}
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
try
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = e.Item
as
GridEditableItem;
RadUpload up = item[
"Attachment"
].Controls[0]
as
RadUpload;
up.OnClientFileSelected =
"ClientFileSelected"
;
}
}
catch
(Exception m)
{
Response.Write(m.Message);
}
}
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
dynamic data =
new
[]{
new
{ID=1,Name=
"Name1"
}
};
RadGrid1.DataSource = data;
}
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
try
{
GridEditableItem item = e.Item
as
GridEditableItem;
RadUpload up = item[
"Attachment"
].Controls[0]
as
RadUpload;
UploadedFile uf = up.UploadedFiles[0];
string
filename = up.UploadedFiles[0].FileName;
}
catch
(Exception m)
{
Response.Write(m.Message);
}
}
}
}
just apply the code in ur local and test
0
Shinu
Top achievements
Rank 2
answered on 29 Nov 2013, 06:35 AM
Hi Ramkumar,
The RadGrid provides a GridAttachmentColumn, there please try to set the UploadControlType property to either RadAsyncUpload or RadUpload for upload to or download from the data source. Please have a look into this online demo. Please elaborate your requirement if it doesn't help you.
Thanks,
Shinu.
The RadGrid provides a GridAttachmentColumn, there please try to set the UploadControlType property to either RadAsyncUpload or RadUpload for upload to or download from the data source. Please have a look into this online demo. Please elaborate your requirement if it doesn't help you.
Thanks,
Shinu.