Loading ...

How to copy a audio file from one file to server in ASP.NET

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » How to copy a audio file from one file to server in ASP.NET

How to copy a audio file from one file to server in ASP.NET

Posts under the topic: How to copy a audio file from one file to server in ASP.NET

Posted: 9/20/2010

Lurker 170  points  Lurker
  • Joined on: 9/16/2010
  • Posts: 34

Hi Guys,

 

 

     Any one know how to copy a audio file from a folder  to server it should be done automatically. When the user copy a file in that folder it should automatically should save in server.


Posted: 9/20/2010

Professional 8505  points  Professional
  • Joined on: 5/3/2010
  • Posts: 391

vamsidhar said:

user="vamsidhar janjanam"]

Hi Guys,

 

 

     Any one know how to copy a audio file from a folder  to server it should be done automatically. When the user copy a file in that folder it should automatically should save in server.

Try using

System.IO.File.Copy("sourceFilePath", "destinationPath", true);

the true is Overwrite option - if set to true, it will overwrite existing file with same name. This param is optional.


Posted: 9/21/2010

Lurker 170  points  Lurker
  • Joined on: 9/16/2010
  • Posts: 34

This will copy the audio file from one folder to data base server.


Posted: 9/21/2010

Professional 8505  points  Professional
  • Joined on: 5/3/2010
  • Posts: 391

vamsidhar said:

user="vamsidhar janjanam"]

This will copy the audio file from one folder to data base server.

What is the difference between databae server and server? What do you mean by database server? If SQL Server, definitely not! If you intend to say Database Server for a server machine you use as a DB server, then, if you point the destination path to that place, it will definitely do.

Please elaborate more on this.


Posted: 9/21/2010

Lurker 170  points  Lurker
  • Joined on: 9/16/2010
  • Posts: 34

Hi 

 

  The think is first the files are in one server not Data Base now we should copy those files to other server where we have different clients.

 

1. we will download the files to one folder then the real work should began after downloading those files to folder then it should automatically copy in other server where we have different clients.It should copy according to the ID given to doctor.

 

 

 

 

I think you had understood if not just ask me i will again explain you clearly


Posted: 9/21/2010

Lurker 270  points  Lurker
  • Joined on: 1/3/2009
  • Posts: 14

Hi vamsidhar,

as per my understanding you will download files on a local system in folder. after that you want to upload these files automaticaly on remote server.

for this you can create a file watcher Utility(windows service) on local system which will track  all changes of files in given folder path. same time you need to create a method to upload file on remote server,  in .net you can perform these task with help of 2 class

1. system.io.filesystemwatcher (http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx )

2.system.net.ftpwebrequest (http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx)

 

may this help you.




Posted: 9/21/2010

Lurker 170  points  Lurker
  • Joined on: 9/16/2010
  • Posts: 34

Hi Rajesh,

 

          The copy should happen according to the ids given to the clients. Every client has one folder so the file which came from one client it should copy in the folder of the same person it should not go in to other folder.Can you help me in this.


Posted: 9/21/2010

Lurker 270  points  Lurker
  • Joined on: 1/3/2009
  • Posts: 14

hi vamsidhar,

If you have One root Folder (Main directory) and clients folder as sub directories you can track all sub directories  by enabling filewatcher property IncludeSubdirectories=true. this will track all sub direcotries changes.


Posted: 9/21/2010

Lurker 170  points  Lurker
  • Joined on: 9/16/2010
  • Posts: 34

Hi Rajesh,

 

          Fine  can you give me any sample code so that i can try it once and do it.I am just thinking how to do it,just provide me one sample code for this problem.


Posted: 9/21/2010

Professional 8505  points  Professional
  • Joined on: 5/3/2010
  • Posts: 391

I didn't mention database anywhere. The method to copy that I've mentioned previolsy does not related to database in any matter.

However, @Rajesh gave you some good directions. Google for some examples and you will see how does this work.

 


Posted: 9/22/2010

Lurker 270  points  Lurker
  • Joined on: 1/3/2009
  • Posts: 14
  Answered

 

vamsidhar said:

user="vamsidhar janjanam"]

Hi Rajesh,

 

          Fine  can you give me any sample code so that i can try it once and do it.I am just thinking how to do it,just provide me one sample code for this problem.

 

Hi vamsidhar,

The links which I have provide you contain sample code and usages of class and methods. You can use same code to perform your task. As there are 2 links so you have to combine code of both links at one place. Simply create a file watcher utility and a file upload method and when an OnCreated event is fired call the file upload method. See following sample code:

 

using System;
using System.IO;
using System.Net;
using System.Security.Permissions;
using System.Text;

namespace FileWatcher
{
    class Program
    {
        static void Main(string[] args)
        {
            Run();
        }
        [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
        public static void Run()
        {
            const string folderPath = @"C:\watcher";
            // Create a new FileSystemWatcher and set its properties.
            FileSystemWatcher watcher = new FileSystemWatcher();
            watcher.Path = folderPath;
           /* Watch for changes in LastAccess and LastWrite times, and the renaming of files or directories. */
            watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                   | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            // Filter all files here you can also filter any specific file type like *.doc or *.xml
            watcher.Filter = "*.*";
            //Include Sub directories 
            watcher.IncludeSubdirectories = true;
            // Add created event handlers.
            watcher.Created += new FileSystemEventHandler(OnCreated);
            // Begin watching.
            watcher.EnableRaisingEvents = true;
            // Wait for the user to quit the program.
            Console.WriteLine("Press \'q\' to quit the sample.");
            while (Console.Read() != 'q') ;
        }

       
        private static void OnCreated(object source, FileSystemEventArgs e)
        {
            // Specify what is done when a file is  created.
            Console.WriteLine("File:{0} created ", e.FullPath);
            UploadFile(e.FullPath, e.Name);
        }

        public static bool UploadFile(string sourceFile, string desinationFileName)
        {
            const string ftpUrl = "ftp://ftphost/wwwroot";//Directory Name where you need to upload file
            string uploadUrl = ftpUrl + @"/" + desinationFileName;
            Uri serverUri = new Uri(uploadUrl);
            if (serverUri.Scheme != Uri.UriSchemeFtp)
            {
                return false;
            }
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri);
            request.Method = WebRequestMethods.Ftp.UploadFile;
            // This example assumes the FTP site uses anonymous logon.
            request.Credentials = new NetworkCredential("ftpusername", "password");
            // Copy the contents of the source file to the request stream.
            StreamReader sourceStream = new StreamReader(sourceFile);
            byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
            sourceStream.Close();
            request.ContentLength = fileContents.Length;

            try
            {
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(fileContents, 0, fileContents.Length);
                requestStream.Close();
                FtpWebResponse response = (FtpWebResponse)request.GetResponse();

                Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

                response.Close();
                return true;
            }
            catch (WebException e)
            {
                Console.WriteLine(e.Message);
                return false;
            }
        }
    }
}

this is a console application. you can also create this as windows service and register this service on the server from which you want to upload the files.


Posted: 9/23/2010

Lurker 170  points  Lurker
  • Joined on: 9/16/2010
  • Posts: 34

Hi Rajesh,

 

 Thanks alot buddy. You all guys helped me alot thanks 


Page 1 of 1 (12 items)