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

How to send return paramters.

1 Answer 67 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Venkata Nagendra Rao
Top achievements
Rank 1
Venkata Nagendra Rao asked on 10 Jan 2011, 03:16 PM
Is there any way i can add return parameters to the handler data so that i can use it back in client??

Here is my code and unfortunately it doesnt work.

string _key = "DocLibKey_";//Used to map the sharepoint site document libraries.
        private static string _fileurl;
        private static Exception _expThrown;
        public override void ProcessStream()
        {
            base.ProcessStream();
              
            try
            {
                if (this.IsFinalFileRequest())
                {
                    string filename = this.Request.Form["RadUAG_fileName"];
                    string physicalfolderpath = HttpContext.Current.Server.MapPath(this.TargetFolder);
                    using (FileStream fstream = new FileStream(physicalfolderpath + "\\" + filename, FileMode.Open))
                    {
                        SPSecurity.RunWithElevatedPrivileges(delegate
                            {
                                //SPSite objSite = new SPSite(SPContext.Current.Web.Url);
                                SPSite objSite = new SPSite("siteurl");
                                using (SPWeb myWeb = objSite.OpenWeb())
                                {
                                    myWeb.AllowUnsafeUpdates = true;
                                    switch (myWeb.Lists[_key + this.TargetFolder].GetType().ToString())
                                    {
                                        case "Microsoft.SharePoint.SPPictureLibrary":
                                            //this.AddReturnParam("Type", myWeb.Lists[_key + this.TargetFolder].GetType().ToString());
                                            SPPictureLibrary objLocationMapLibrary = (SPPictureLibrary)myWeb.Lists[_key + TargetFolder];
                                            SPFile spPictureFile = objLocationMapLibrary.RootFolder.Files.Add(filename, fstream, true);
                                            if (spPictureFile != null)
                                            {
                                                //this.Result.Add("FileURL", spPictureFile.Url);
                                                _fileurl = spPictureFile.Url;
                                            }
                                            break;
                                        default:
                                            //this.AddReturnParam("Type", myWeb.Lists[_key + this.TargetFolder].GetType().ToString());
                                            SPFile spDocLibFile = myWeb.Lists[_key + TargetFolder].RootFolder.Files.Add(filename, fstream, true);
                                            if (spDocLibFile != null)
                                            {
                                                //this.Result.Add("FileURL", spDocLibFile.Url);
                                                _fileurl = spDocLibFile.Url;
                                            }
                                            break;
                                    }
  
                                    myWeb.AllowUnsafeUpdates = false;
                                }
                            }
                        );
                    }
                    //base.GetAssociatedData().Add("FileURL", "xyz");
                    //this.AddReturnParam("FileURL", "xyz");
                    //_fileurl="xyz";
                    File.Delete(physicalfolderpath + "\\" + filename);
                }
            }
            catch (Exception exp)
            {
                _expThrown = exp;
                //this._result.Add("EXCEPTION", exp);
            }
  
        }
                         
        public override Dictionary<string, object> GetAssociatedData()
        {
            Dictionary<string, object> associatedData = base.GetAssociatedData();
            if (this.IsFinalFileRequest())
            {
                if (_fileurl != null)
                {
                    if (!associatedData.ContainsKey("FileURL"))
                        associatedData.Add("FileURL", _fileurl);
                }
                if (_expThrown != null)
                {
                    if (!associatedData.ContainsKey("EXCEPTION"))
                        associatedData.Add("EXCEPTION", _expThrown);
                }
            }
            return associatedData;
        }

Once the file got uploaded from silverlight to the server folder specified then the process for uploading the file to sharepoint document libraray or picture libraray starts. Once the file got uploaded to the directory then the URL of the file should be returned to client so that the url will be saved in the Database.

I tried several ways and none working. I even used the AddReturnParam with value and key.
There is no exception or error. In the server it adds properly but in client i couldnt able to see any values.
Let me know what is wrong with the code. For me this looks like a bug as any control after extending & overriding you should be able to add values into base return type after the main process is completed.

Regards,
Nagendra

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 11 Jan 2011, 05:46 PM
Hello Venkata Nagendra Rao,

During the past year a few changes were introduced in the RadUpload control. More info you can find here. Moreover, you can have a look at this article about the upload service parameters and how to pass parameters between the client and the server sides.

I hope this info will help you implement your scenario. Also, you can examine the RadUpload scenarios illustrated in our KB section. They will help you get a better glimpse of the common implementations of the control's functionality.

 If we can further assist you, please let us know.

Greetings,
Tina Stancheva
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Upload
Asked by
Venkata Nagendra Rao
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or