I have followed your example on implementing the DBContentProvider for our editor and it works pretty good. Uploading and deleting works great. I am having a problem with renaming though. I can right click on the file and select Rename, enter the new name and click OK, but the filename never changes in the database.
Can you tell me where to look?
I attempted to do this in your demo and it also didn't work when renaming folders.
I am using the latest internal build and FF 3.0.8
Shawn
Can you tell me where to look?
I attempted to do this in your demo and it also didn't work when renaming folders.
I am using the latest internal build and FF 3.0.8
Shawn
4 Answers, 1 is accepted
0
Accepted
Hi,
I think the rename/move has not been implemented in the database provider example yet. I will make sure that the example is updated.
Here is the code you need to add to the content provider class:
and here is the UpdateItemPath() function, that should be added to the DataServer class:
Best wishes,
Lini
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
I think the rename/move has not been implemented in the database provider example yet. I will make sure that the example is updated.
Here is the code you need to add to the content provider class:
public override string MoveFile(string path, string newPath) |
{ |
try |
{ |
string newFileName = GetName(newPath); |
string newFilePath = newPath.Substring(0, newPath.Length - newFileName.Length); |
DataRow newPathRow = DataServer.GetItemRow(newFilePath); |
DataServer.UpdateItemPath(path, newFileName, (int)newPathRow["ItemID"]); |
} |
catch (Exception e) |
{ |
return e.Message; |
} |
return string.Empty; |
} |
public override string MoveDirectory(string path, string newPath) |
{ |
if (newPath.EndsWith("/")) newPath = newPath.Remove(newPath.Length - 1, 1); |
return MoveFile(path, newPath); |
} |
and here is the UpdateItemPath() function, that should be added to the DataServer class:
public void UpdateItemPath(string path, string newName, int newParentId) |
{ |
int itemId = GetItemId(path); |
if (itemId < 0) |
{ |
return; |
} |
OleDbCommand command = new OleDbCommand("UPDATE Items SET [Name]=@Name, ParentId=@ParentId WHERE ItemID=@ItemID", Connection); |
command.Parameters.Add(new OleDbParameter("@Name", newName)); |
command.Parameters.Add(new OleDbParameter("@ParentId", newParentId)); |
command.Parameters.Add(new OleDbParameter("@ItemID", itemId)); |
Connection.Open(); |
command.ExecuteNonQuery(); |
CloseConnection(); |
} |
Best wishes,
Lini
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0

hacker
Top achievements
Rank 1
answered on 02 Apr 2009, 04:27 PM
Hi Lini,
Thanks for that code, it seems to be almost perfect. The moving of files works fine, but renaming doesn't. I found that when the MoveFile Function is called furing a rename, the newPath value is just the filename, not the full path. What happens is the file is renamed, but then moved to the very top level with a parentID of 1. If the full path was passed, I think it would work perfectly. I tested it in IE 7 and FF 3.0.8.
The example I tried was to rename a file that was in the /images/editor/ folder. The file was called preview.png.
The editor folder has an ID of 88 and the preview.png file has a parentID of 88. But when renaming, the file is renamed and the parentID also gets changed to 1 (the root parent id).
Hopefully I've explained myself clear enough.
Shawn
Thanks for that code, it seems to be almost perfect. The moving of files works fine, but renaming doesn't. I found that when the MoveFile Function is called furing a rename, the newPath value is just the filename, not the full path. What happens is the file is renamed, but then moved to the very top level with a parentID of 1. If the full path was passed, I think it would work perfectly. I tested it in IE 7 and FF 3.0.8.
The example I tried was to rename a file that was in the /images/editor/ folder. The file was called preview.png.
The editor folder has an ID of 88 and the preview.png file has a parentID of 88. But when renaming, the file is renamed and the parentID also gets changed to 1 (the root parent id).
Hopefully I've explained myself clear enough.
Shawn
0
Accepted
Hello,
Thanks for the feedback! With a little modification to the MoveFile method, the renaming should work just fine:
I added an additional check - if the new path has only the file name, then we do not change the parent.
Kind regards,
Lini
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Thanks for the feedback! With a little modification to the MoveFile method, the renaming should work just fine:
public override string MoveFile(string path, string newPath) |
{ |
try |
{ |
string newFileName = GetName(newPath); |
string newFilePath = newPath.Substring(0, newPath.Length - newFileName.Length); |
if (newFilePath.Length == 0) |
{ |
newFilePath = path.Substring(0, path.LastIndexOf("/")); |
} |
DataRow newPathRow = DataServer.GetItemRow(newFilePath); |
DataServer.UpdateItemPath(path, newFileName, (int)newPathRow["ItemID"]); |
} |
catch (Exception e) |
{ |
return e.Message; |
} |
return string.Empty; |
} |
I added an additional check - if the new path has only the file name, then we do not change the parent.
Kind regards,
Lini
the Telerik team
Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0

hacker
Top achievements
Rank 1
answered on 03 Apr 2009, 12:41 PM
Lini,
That works great now! Thanks!
Shawn
That works great now! Thanks!
Shawn