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

[Solved] how to remove file from DB by cliking remove button in Telerik upload control

2 Answers 127 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
makram
Top achievements
Rank 1
makram asked on 04 Jul 2011, 04:30 PM
Greetings,

i m using upload control asp.net MVC.
Upload.Multiple(true).Async(a => a.AutoUpload(true)
.Save("SaveFile""Fichier"new { Area = "" })
.Remove("RemoveFile""Fichier"new { Area = "" }));

in the list of uploaded file i have only fileName of each file i did upload.

my controller ;

[HttpPost]         
public ActionResult SaveFile()
{
var files = this.HttpContext.Request.Files;             
var dbFile = new BinaryField();             
if (files != null)             {                 
for (int i = 0; i < files.Count; i++)                
 {                     
dbFile.Title = Path.GetFileNameWithoutExtension(files[i].FileName);                    
 dbFile.Content = GetFileBytes(files[i]);                     
dbFile.Ext = Path.GetExtension(files[i].FileName);                    
 dbFile.Ext = files[i].ContentType;                  
 RepositoryInstance.SaveOrUpdate(dbFile);                 
}             
}             //return Content("");             
return Json(new { Succces = true, Content = dbFile.Id, });             
//return Json(new { id = dbFile.Id }, "text/plain");         
}         
[HttpPost]         
public ActionResult RemoveFile(string fileNames)        
{             
int id = 22;             
var
 dbFile = new BinaryField();             
dbFile = RepositoryInstance.Get(id);             
RepositoryInstance.Delete(dbFile);             
RepositoryInstance.DbContext.CommitChanges();             
//return Content("");
            
return
 Json(new { status = "OK" }, "text/plain");         
}

how to deal whith RemoveFile to be able to remove file from DB using it's ID i got as json response in my SaveFile()
??

Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Alexandre Jobin
Top achievements
Rank 1
answered on 02 Aug 2011, 08:39 PM
i also have the same question on my side. I need to identify which file the user want to remove. The name of the file is not good for me. I need a custom id!

thank you for the help!

alex
0
Jared
Top achievements
Rank 1
answered on 12 Aug 2011, 10:32 PM
I'm in the exact same bind...

Found this though, it uses a Grid to manage file uploads. I'm going to implement this since it does everything I need. Hope it helps you two as well...

http://www.telerik.com/community/code-library/aspnet-mvc/upload/uploading-files-to-a-database.aspx
Tags
Upload
Asked by
makram
Top achievements
Rank 1
Answers by
Alexandre Jobin
Top achievements
Rank 1
Jared
Top achievements
Rank 1
Share this question
or