Vectorlight News

  • Chat App Converted to HTML and JQuery
    Sep 08, 2011

    Converted from Silverlight to HTML and Javascript/JQuery is the Vectorlight Chat App. Login using your Vectorlight password to chat using your username and avatar.

  • HTML5 iPhone,Android Big Guns Tower Defense
    Jul 02, 2011

    Big Guns has made the leap from Windows Phone 7 (XNA) to HTML5 so you can now play it on your iPhone, Android and other HTML5 compatible devices.

  • HTML5 Games - Word Poppers and Batty
    Jun 04, 2011

    As the take-up of HTML5 quickens (74% of users currently have a browser capable of HTML5 Canvas) we present two more games for both your browser and mobile.

  • Big Guns Tower Defense on Windows Phone 7
    May 06, 2011

    Coming soon to Windows Phone 7 is an XNA port of the popular Vectorlight tower defense game Super Tower Defense. Whilst retaining many of the graphical and gameplay features of the original Silverlight game.

  • Wakacube WP7 Update
    Apr 26, 2011

    Released to the Windows Phone 7 marketplace today is Version 1.1 of Wakacube the 3D physics game of skill. Included in the update are more levels (30 in total) and new mode Wakatime which generates random crate structures to keep players entertained long after the levels have been completed.

  • Home Page News
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!

 
 

Rate this: 

1 Star 2 Star 3 Star 4 Star 5 Star
8 Ratings / 2.5 Average