Save File Information to database

4 posts, 0 answers
  1. Charlotte
    Charlotte avatar
    3 posts
    Member since:
    Feb 2011

    Posted 13 Apr 2011 Link to this post

    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
  2. coding
    coding avatar
    6 posts
    Member since:
    Apr 2011

    Posted 13 Apr 2011 Link to this post

    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;

     

     

    }

  3. DevCraft banner
  4. Charlotte
    Charlotte avatar
    3 posts
    Member since:
    Feb 2011

    Posted 14 Apr 2011 Link to this post

    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



  5. coding
    coding avatar
    6 posts
    Member since:
    Apr 2011

    Posted 14 Apr 2011 Link to this post

    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.
Back to Top