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

Save File Information to database

3 Answers 122 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Charlotte
Top achievements
Rank 1
Charlotte asked on 14 Apr 2011, 02:11 AM
Hello Guys,

I am using the Radupload silve light contorl to upload files . Here is what I am trying to achieve after every file uploaded to Target folder , I want to save the file information like fileName , FolderPath to a database table.

I do see couple of examples overriding the Process Request Method and using IsFinalFileRequest() method , but the problem is IsFinalFileRequest() method gets fired only at end of last file when I am uploading the multiple files.

Can you guys give me an example on how to Write information to a database table after each file uploaded to the Target folder ?

Thanks,
Ajay

3 Answers, 1 is accepted

Sort by
0
coding
Top achievements
Rank 1
answered on 14 Apr 2011, 03:04 AM
Ajay, not sure if this will help you or not but....sorry the paste did not work as well as expected.  This method goes in the class that derives from RadUploadHandler.


public
override bool SaveChunkData(string filePath, long position, byte[] buffer, int contentLength, out int savedBytes)
{
    bool result = base.SaveChunkData(filePath, position, buffer, contentLength, out savedBytes);

    // Checks if this is the last chunk of each file

 

 

 

 

    if (this.IsFinalFileRequest()) 
    
{
        
//if the file is successfully uploaded  
        
if (result) 
        
{

 

 

            try

 

            {

 

                //probably a better way to do this instead of reading it back from the file system
                FileStream
fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); 
                
BinaryReader rdr = new BinaryReader(fs); 
                
long fileLength = fs.Length;

 

                 byte[] docData = rdr.ReadBytes((

 

int)fs.Length);
                
rdr.Close();
                fs.Close();

 

 

 

                
                string filename =
Path.GetFileName(filePath);
                
string ext = Path.GetExtension(filePath);

                //make your call to the database here

 

 

            }

 

 

 

            catch (Exception ex)             

            { 

 

                //do exection handling

            } 
        
}

    }

 

    return result;

 

 

}

0
Charlotte
Top achievements
Rank 1
answered on 14 Apr 2011, 04:38 PM
I copied your code but it's not firing the Save Chunk Data event in my Handler . Also I don't see the SaveChunk method in the intellisense.

Is SaveChunkData something new in this version ?

Ajay



0
coding
Top achievements
Rank 1
answered on 14 Apr 2011, 04:48 PM
Hey Ajay,

This is where I located the example I used to create the code below:  http://www.telerik.com/community/forums/silverlight/upload/tilde-in-uploadserviceurl-ignores-virtual-dir.aspx.  The 4th reply from the top provides an example for both stream and file.  I used the file based mechanism but the stream might be better.  I have not looked at it but my guess is that it allows you to save the file to the database without first writing it to the local file system.

I am using the latest Silverlight controls the Q1 2011 release.
Tags
Upload
Asked by
Charlotte
Top achievements
Rank 1
Answers by
coding
Top achievements
Rank 1
Charlotte
Top achievements
Rank 1
Share this question
or