Latest News

  • Super Tower Defense Game
    Mar 10, 2010

    New to the games section is the new Super Tower Defense game. Defend your base from the ever advancing army of tanks, buggies...

  • New Rich Text Editor User Control
    Feb 19, 2010

    By popular request, here we present a re-usable User Control containing the Liquid RichTextBox along with the most common formatting functions included.

  • Silverlight 3 Controls V5.2.7 Released
    Feb 19, 2010

    This release includes several fixes for issues raised in the forum. The main improvement is to the RichTextBox which now provides access and methods to the document elements allowing...

  • Super Shoot Em Up Game
    Feb 04, 2010

    Added to the games section is the new Super Shoot 'Em Up game. Take control of a tank with your aim being to blow up your opposing tanks and collect all the powerups.

  • Silverlight 3 Controls V5.2.6 Released
    Feb 04, 2010

    This release includes some minor fixes for several forum posts. Please see the notes on the download page for full details on what has changed.

lancem
lancem
Changing the file name in the target location Posted: Nov 18, 2009
 

Hi,


I'm want to upload a file to the webserver and rename it so it is the old file name + an id so that it won't get overwritten and I can associate it with the relevant record.  One of the overloads for the UpdateFile method has a parameter targetFileName which I hoped to use but it has no effect.  Am I missing something?  Please help.


Thanks

 
 
dan
dan
RE: Changing the file name in the target location Posted: Nov 20, 2009
 

Hi,


Yes, this is what this is used for.  How have you implemented your web service, could you post the function declaration?


Thanks!

 
 
lancem
lancem
RE: Changing the file name in the target location Posted: Nov 25, 2009
 

Hi Dan,


Thanks for your reply.  I've implemented almost exactly as the example.  Below is the code:

  /// <summary>

   /// Summary description for FileUploadService

   /// </summary>

   [WebService(Namespace = "http://tempuri.org/")]

   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

   [System.ComponentModel.ToolboxItem(false)]

   public class FileUploadService : System.Web.Services.WebService

   {

      public FileUploadService()

      {


      }


      [WebMethod]

      public string Upload(string mode, string path, string name, string filedata, bool overwrite)

      {

         string fullpath = string.Empty;

         string filename = string.Empty;

         try

         {

            fullpath = Server.MapPath("~") + @"\" + path.Replace("/", @"\");

            filename = fullpath + name;


            if(!Directory.Exists(fullpath))

            {

               Directory.CreateDirectory(fullpath);

            }


            if (mode == "new")

            {

               if (File.Exists(filename))

               {

                  if (overwrite)

                  {

                     File.Delete(filename);

                  }

                  else

                  {

                     return "File Already Exists";

                  }

               }

               WriteFile(filename, Convert.FromBase64String(filedata), FileMode.Create);

            }

            else

            {

               WriteFile(filename, Convert.FromBase64String(filedata), FileMode.Append);

            }

         }

         catch (Exception ex)

         {

            File.Delete(filename);

            return "File Write Error: " + ex.Message;

         }


         return "ok";

      }


      [WebMethod]

      public void DeleteUploadedFile(string fileLocation, string fileName)

      {

         try

         {

            string strPathAndFile = Server.MapPath("~") + @"\" + fileLocation + fileName;


            if (File.Exists(strPathAndFile))

            {

               File.Delete(strPathAndFile);

            }

         }

         catch

         {


         }

      }


      private void WriteFile(string filename, byte[] content, FileMode fileMode)

      {

         Stream target = null;

         BinaryWriter writer = null;

         try

         {

            target = File.Open(filename, fileMode);

            writer = new BinaryWriter(target);

            writer.Write(content);

         }

         catch (Exception ex)

         {

            throw new Exception("Could not write to file: " + filename + " - " + ex.Message);

         }

         finally

         {

            if (target != null)

            {

               target.Close();

            }

            if (writer != null)

            {

               writer.Close();

            }

         }

      }

   }


Please help.


Lance

 
 
dan
dan
RE: Changing the file name in the target location Posted: Nov 28, 2009
 

Hi Lance,


Apologies for this, the web service has changed and I think I have given you the wrong method stub, the Upload() method should have the following signature:


public string Upload(string id, string mode, string path, string name, string filedata, bool overwrite, string tag, bool final)


I have updated the download on the site to reflect this.  Could you give it a try and let me know if you still have problems?


Thanks!

 
 
lancem
lancem
RE: Changing the file name in the target location Posted: Dec 01, 2009
 

Hi Dan,


Thanks for your help.  Changing the Upload signature helped me achieve my goal.  The "targetFileName" parameter still had no effect and didn't come through to the Upload function of the web service, but this time the "id" parameter came through and I was able to rename the file accordingly in the Upload function of the web service.  


Again, thanks for your help and your great controls.


Lance

 
 
dan
dan
RE: Changing the file name in the target location Posted: Dec 24, 2009
 

Hi Lance,


I have modified the demo and integrated it with a test website.  This can be downloaded from the demos page as usual and should help point you in the right direction.


Thanks!