Пример #1
0
        private string BuildDirHTML(Dir422 Directory)
        {
            var html = new System.Text.StringBuilder("<html>");

            html.Append("<h1>Folders</h1>");

            // PERCENT ENCODE HERE
            //get rid of ( # reserved html key)!!!!!!
            foreach (Dir422 Dir in Directory.GetDirs())
            {
                html.AppendFormat(
                    "<a href=\"{0}\">{1}</a><br>", Utility.AbsolutePath(Dir), Dir.Name
                    );
            }

            html.Append("<h1>Files</h1>");

            foreach (File422 file in Directory.GetFiles())
            {
                html.AppendFormat(
                    "<a href=\"{0}\">{1}</a><br>", Utility.AbsolutePath(file.Parent) + "/" + file.Name, file.Name
                    );
            }

            html.Append("<html>");
            return(html.ToString());
        }
Пример #2
0
        private bool ContainsFileRecursive(string fileName, Dir422 dir)
        {
            IList <File422> files = dir.GetFiles();

            foreach (File422 file in files)
            {
                if (file.Name == fileName)
                {
                    return(true);
                }
            }

            // Get the current dir's subdirs
            IList <Dir422> subDirs = dir.GetDirs();

            //Here we have looked at all the files in our directory and did nt
            // find our filename, now we need to look in a subdirectory
            foreach (Dir422 subDir in subDirs)
            {
                if (ContainsFileRecursive(fileName, subDir))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        string BuildDirHTML(Dir422 directory)
        {
            var root  = directory.Name + "/";
            var files = directory.GetFiles();
            var dirs  = directory.GetDirs();

            Console.WriteLine("inside build {0} dirs, {1} files", dirs.Count, files.Count);

            var dirStr = "";
            var path   = getPath(directory);

            Console.WriteLine("-------------------------");
            Console.WriteLine(path);

            foreach (var dir in dirs)
            {
                dirStr += String.Format(RESPONSE_ENTRY_FORMAT, path + dir.Name, dir.Name);
            }
            var fileStr = "";

            foreach (var file in files)
            {
                fileStr += String.Format(RESPONSE_ENTRY_FORMAT, path + file.Name, file.Name);
            }

            return(String.Format(RESPONSE_FORMAT, dirStr, fileStr));
        }
Пример #4
0
        string BuildDirHTML(Dir422 dir)
        {
            _cwd = new StringBuilder();
            // Generate Html
            var html = new StringBuilder("<html> <h1>Folders</h1>");

            // Append dirs
            foreach (Dir422 d in dir.GetDirs())
            {
                // Construct cwd href as we go
                string cwd = ConstructCWD(dir);

                Console.WriteLine("cwd: " + cwd.ToString());
                Console.WriteLine("d.name: " + d.Name);
                html.AppendFormat("<a href=\"{0}/{1}\">{1}</a> <br>", cwd, d.Name);
            }

            html.AppendLine("<h1>Files</h1>");

            foreach (File422 file in dir.GetFiles())
            {
                string cwd = ConstructCWD(file);

                Console.WriteLine("cwd: " + cwd.ToString());
                Console.WriteLine("file.name: " + file.Name);
                html.AppendFormat("<a href=\"{0}/{1}\">{1}</a> <br>", cwd, file.Name);
            }

            html.AppendLine("</html>");
            return(html.ToString());
        }
Пример #5
0
        string BuildDirHTML(Dir422 directory)
        {
            StringBuilder builder = new StringBuilder();

            // Styling
            builder.Append("<html>");
            builder.Append("<head><style>");

            // It's gotta look stylish right?
            builder.Append(" tr:nth-child(even) {background-color: #f2f2f2} ");
            builder.Append(" table { text-align : center; border: 2px solid black } ");
            builder.Append(" .center { position: absolute; width : 75%; left: 12.5% } ");
            builder.Append(" h1 { font-size: 4em } ");
            builder.Append(" a { font-size: 2em } ");
            builder.Append("</style>");
            builder.Append("</head>");
            builder.Append("<body style='text-align:center'><div class='center'>");
            builder.Append("<h1>Directories</h1>");

            // Get all directories
            builder.Append("<table width='100%'>");
            foreach (var dir in directory.GetDirs())
            {
                // Need to get rid of '**/{current_dir}/' in uri
                string uri = ServiceURI + "/" + FullPath.Make(directory, Uri.EscapeDataString(dir.Name)).Replace(fileSystem.GetRoot().Name + "/", "");

                builder.Append("<tr><td><a href='" + uri + "'>" + dir.Name + "</a></td></tr>");
            }
            builder.Append("</table>");

            builder.Append("<h1>Files</h1>");
            // Get all files
            builder.Append("<table width='100%'>");


            foreach (var file in directory.GetFiles())
            {
                // Need to get rid of '**/{current_dir}/' in uri
                string uri = ServiceURI + "/" + FullPath.Make(directory, Uri.EscapeDataString(file.Name)).Replace(fileSystem.GetRoot().Name + "/", "");

                builder.Append("<tr><td><a href='" + uri + "'>" + file.Name + "</a></td></tr>");
            }
            builder.Append("</table>");

            // Add the abillity to upload files
            if (allowUploads)
            {
                builder.Append(SCRIPT);
                builder.AppendFormat(
                    "<hr><h3 id='uploadHdr'>Upload</h3><br>" +
                    "<input id=\"uploader\" type='file' " +
                    "onchange='selectedFileChanged(this,\"{0}\")' /><hr>",
                    GetHREF(directory, true));
            }

            builder.Append("</div></body></html>");

            return(builder.ToString());
        }
Пример #6
0
        public void MemFSDirGetDirsTest()
        {
            IList <Dir422> dirs = root.GetDirs();
            Dir422         one  = root.GetDir("one");
            Dir422         two  = root.GetDir("two");

            Assert.AreEqual(2, dirs.Count);
            Assert.AreSame(one, dirs[dirs.IndexOf(one)]);
            Assert.AreSame(two, dirs[dirs.IndexOf(two)]);
        }
Пример #7
0
        private string BuildDirHTML(Dir422 directory)
        {
            StringBuilder html = new StringBuilder("");

            //Files
            String dirPath = "";
            Dir422 temp    = directory;

            while (temp.Parent != null)
            {
                dirPath = temp.Name + "/" + dirPath;
                temp    = temp.Parent;
            }
            dirPath = ServiceURI + "/" + dirPath;

            if (directory.GetFiles().Count > 0)
            {
                html.AppendLine("<h1 style=\"color:black;\">Files</h1>");
            }
            foreach (File422 file in directory.GetFiles())
            {
                //string name = PercentEncoding(file.Name);
                //string href = dirPath + name;
                string href = dirPath + file.Name;
                html.AppendFormat("<a href=\"{0}\">{1}</a>   <br>", href, file.Name);
            }

            //Directories
            //General Note: Don't forget percent encoding and decoding.
            if (directory.GetDirs().Count > 0)
            {
                html.AppendLine("<hr></hr><h1 style=\"color:black;\">Folders</h1>");
            }
            foreach (Dir422 d in directory.GetDirs())
            {
                //string name = PercentEncoding(d.Name);
                //string href = dirPath + name;
                string href = dirPath + d.Name;
                html.AppendFormat("<a href=\"{0}\">{1}</a>   <br>", href, d.Name);
            }
            return(html.ToString());
        }
Пример #8
0
        private string BuildDirHTML(Dir422 directory)
        {
            StringBuilder foldersBuilder = new StringBuilder();
            StringBuilder filesBuilder   = new StringBuilder();

            var dirs  = directory.GetDirs();
            var files = directory.GetFiles();

            const string nodeTemplate = "<a href=\"" + _route + "{0}\">{1}</a><br>";
            string       path         = "";

            if (dirs.Count > 0)
            {
                path = BuildPath(directory);
                foldersBuilder.Append("<h1>Folders</h1>");
                foreach (Dir422 dir in dirs)
                {
                    string dirName = dir.Name.Replace("#", "%23");
                    foldersBuilder.Append(
                        String.Format(nodeTemplate,
                                      path + "/" + dirName, dir.Name)
                        );
                }
            }

            if (files.Count > 0)
            {
                path = BuildPath(directory);
                filesBuilder.Append("<h1>Files</h1>");
                foreach (File422 file in files)
                {
                    string fileName = file.Name.Replace("#", "%23");
                    filesBuilder.Append(
                        String.Format(nodeTemplate,
                                      path + "/" + fileName, file.Name)
                        );
                }
            }

            string formattedResponse = "";

            if (files.Count == 0 && dirs.Count == 0)
            {
                formattedResponse = "<html><h1>Empty Directory.</h1></html>";
            }
            else
            {
                formattedResponse = String.Format("<html>{0}{1}</html>",
                                                  foldersBuilder.ToString(), filesBuilder.ToString());
            }


            return(formattedResponse);
        }
Пример #9
0
        private void RespondWithList(Dir422 dir, WebRequest req)
        {
            var html = new System.Text.StringBuilder("<html>");

            var    files   = dir.GetFiles();
            var    dirs    = dir.GetDirs();
            string dirPath = "";

            Dir422 temp = dir;

            dirPath = "/files";

            string tempPath = "";

            while (temp.Parent != null)
            {
                tempPath = "/" + temp.Name + tempPath;
                temp     = temp.Parent;
            }
            dirPath = dirPath + tempPath + "/";



            html.Append("<h1> Folders</h1>");

            foreach (var d in dirs)
            {
                string href = dirPath + d.Name;
                html.AppendFormat("<a href=\"{0}\">{1}</a><br />", href, d.Name);
            }

            html.Append("<h1> Files</h1>");

            foreach (var f in files)
            {
                // makesure dirPath has only one / at the end
                // TODO
                string href = dirPath + f.Name;
                html.AppendFormat("<a href=\"{0}\">{1}</a><br />", href, f.Name);
            }

            html.Append("</HTML>");

            req.WriteHTMLResponse(html.ToString());

            Console.WriteLine("SENT LIST");
            return;
        }
Пример #10
0
        public override bool ContainsFile(string fileName, bool recursive)
        {
            if (fileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                return(false);
            }
            bool found = false;

            if (recursive == false)
            {
                for (int i = 0; i < _files.Count && found != true; i++)
                {
                    if (_directories[i].Name == fileName)
                    {
                        found = true;
                    }
                }
                return(found);
            }
            Queue <Dir422> Dirs = new Queue <Dir422>();

            Dirs.Enqueue(this);
            while (!found && Dirs.Count > 0)
            {
                //get top folder
                Dir422 temp = Dirs.Dequeue();

                //look through it's directories and see if they are what we want
                foreach (var d in temp.GetFiles())
                {
                    if (fileName == d.Name)
                    {
                        found = true;
                    }
                    // enqueue all the directories so we can contiune searching deeper
                    foreach (var s in temp.GetDirs())
                    {
                        Dirs.Enqueue(s);
                    }
                }
            }
            return(found);
        }
Пример #11
0
        private bool ContainsDirRecursive(string dirName, Dir422 dir)
        {
            if (dir.Name == dirName)
            {
                return(true);
            }

            // Get the current dir's subdirs
            IList <Dir422> subDirs = dir.GetDirs();

            foreach (Dir422 subDir in subDirs)
            {
                if (ContainsDirRecursive(dirName, subDir))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #12
0
        private string BuildDirHTML(Dir422 directory)
        {
            var html = new System.Text.StringBuilder("<html>");

            html.Append("<h1>Files</h1>");

            foreach (File422 file in directory.GetFiles())
            {
                string path = GetPath(file.Parent);
                path += "/" + file.Name;

                // percent incode from our filename
                path = Uri.EscapeUriString(path);

                html.AppendFormat(
                    "<a href=\"{0}\">{1}</a>",
                    path, file.Name
                    );
                html.Append("<br>");
            }

            html.Append("<h1>Directories</h1>");

            foreach (Dir422 dir in directory.GetDirs())
            {
                string path = GetPath(dir);

                html.AppendFormat(
                    "<a href=\"{0}\">{1}</a>",
                    path, dir.Name
                    );

                html.Append("<br>");
            }



            html.AppendLine("</html>");

            return(html.ToString());
        }
Пример #13
0
        //when a directory is requested
        private void RespondWithList(Dir422 dir, WebRequest req)
        {
            var html = new System.Text.StringBuilder("<html>");

            //DIR STUFF
            html.Append("<h1>Folders</h1>");

            foreach (Dir422 directory in dir.GetDirs())
            {
                html.Append(BuildDirHTML(directory));
            }


            //FILE STUFF
            html.Append("<h1>Files</h1>");

            foreach (File422 file in dir.GetFiles())
            {
                html.AppendFormat(BuildFileHTML(file));
            }

            html.AppendLine("</html>");
            req.WriteHtmlResponse(html.ToString());
        }
Пример #14
0
        String BuildDirHTML(Dir422 directory)
        {
            var html = new StringBuilder("<html>");

            if (m_allowUploads)
            {
                html.AppendLine(
                    @"<script> 
                function selectedFileChanged(fileInput, urlPrefix) {     
                    document.getElementById('uploadHdr').innerText = 'Uploading ' + fileInput.files[0].name + '...'; 
                    
                    //Need XMLHttpRequest to do the upload     
                    if (!window.XMLHttpRequest)     {         
                        alert('Your browser does not support XMLHttpRequest. Please update your browser.');         
                        return;     
                    } 
 
                    //Hide the file selection controls while we upload     
                    var uploadControl = document.getElementById('uploader');     
                    if (uploadControl)     
                    {         
                        uploadControl.style.visibility = 'hidden';     
                    } 
 
                    // Build a URL for the request     
                    if (urlPrefix.lastIndexOf('/') != urlPrefix.length - 1)     
                    {         
                        urlPrefix += '/';     
                    } 

                    var uploadURL = urlPrefix + fileInput.files[0].name; 
 
                    //Create the service request object     
                    var req = new XMLHttpRequest();     
                    req.open('PUT', uploadURL);
                    req.onreadystatechange = function(){         
                        document.getElementById('uploadHdr').innerText = 'Upload (request status == ' + req.status + ')';
                        // Un-comment the line below and comment-out the line above if you want the page to          
                        // refresh after the upload         
                        //location.reload();     
                    };     
                    req.send(fileInput.files[0]); 
                } 
                </script> "
                    );
            }

            html.AppendLine("<h1>Folders</h1>"); //label the beginning of folders
            foreach (Dir422 dir in directory.GetDirs())
            {
                html.AppendLine(
                    String.Format("<a href=\"{0}\">{1}</a>", GetHREFFromDir422(dir), dir.Name) //FIX THIS, first one should be full path
                    );
                html.AppendLine("</br>");
            }

            html.AppendLine("<h1>Files</h1>"); //label the beginning of files

            foreach (File422 file in directory.GetFiles())
            {
                html.AppendLine(
                    String.Format("<a href=\"{0}\">{1}</a>", GetHREFFromFile422(file), file.Name) //FIX THIS, first one should be full path
                    );
                html.AppendLine("</br>");                                                         //append new lines for styling
            }

            if (m_allowUploads) //if you can upload, show the upload button and browser
            {
                html.AppendFormat(
                    "<hr><h3 id='uploadHdr'>Upload</h3><br>" +
                    "<input id=\"uploader\" type='file' " +
                    "onchange='selectedFileChanged(this,\"{0}\")' /><hr>",
                    uriPath //give a reference to this folder
                    );
            } //end uploading area

            html.AppendLine("</html>");
            return(html.ToString());
        }
Пример #15
0
        private string BuildDirHTML(Dir422 directory)
        {
            var html = new System.Text.StringBuilder("<html>");

            // We'll need a bit of script if uploading is allowed
            if (m_allowUploads)
            {
                html.AppendLine(
                    @"<script>
						function selectedFileChanged(fileInput, urlPrefix)
						{
							 document.getElementById('uploadHdr').innerText = 'Uploading ' + fileInput.files[0].name + '...';
							 // Need XMLHttpRequest to do the upload
							 if (!window.XMLHttpRequest)
							 {
								 alert('Your browser does not support XMLHttpRequest. Please update your browser.');
								 return;
							 }
							 // Hide the file selection controls while we upload
							 var uploadControl = document.getElementById('uploader');
							 if (uploadControl)
							 {
							    uploadControl.style.visibility = 'hidden';
							 }
							 // Build a URL for the request
							 if (urlPrefix.lastIndexOf('/') != urlPrefix.length - 1)
							 {
							    urlPrefix += '/';
							 }

							 var uploadURL = urlPrefix + fileInput.files[0].name;
							 // Create the service request object
							 var req = new XMLHttpRequest();
							 req.open('PUT', uploadURL);
							 req.onreadystatechange = function()
							 {
							    document.getElementById('uploadHdr').innerText = 'Upload (request status == ' + req.status + ')';
							 };
							 req.send(fileInput.files[0]);
						}
					</script>
				"                );
            }

            html.Append("<h1>Files</h1>");

            foreach (File422 file in directory.GetFiles())
            {
                string path = GetPath(file.Parent);
                path += "/" + file.Name;

                // percent incode from our filename
                path = Uri.EscapeUriString(path);

                html.AppendFormat(
                    "<a href=\"{0}\">{1}</a>",
                    path, file.Name
                    );
                html.Append("<br>");
            }

            html.Append("<h1>Directories</h1>");

            foreach (Dir422 dir in directory.GetDirs())
            {
                string path = GetPath(dir);

                html.AppendFormat(
                    "<a href=\"{0}\">{1}</a>",
                    path, dir.Name
                    );

                html.Append("<br>");
            }


            if (m_allowUploads)
            {
                html.AppendFormat(
                    "<hr><h3 id='uploadHdr'>Upload</h3><br>" +
                    "<input id=\"uploader\" type='file' " +
                    "onchange='selectedFileChanged(this,\"{0}\")' /><hr>",
                    GetPath(directory));
            }


            html.AppendLine("</html>");

            return(html.ToString());
        }
Пример #16
0
        string BuildDirHTML(Dir422 dir)
        {
            var html = new System.Text.StringBuilder("<html><h1>Folders</h1>");

            // Build an HTML file listing
            // We'll need a bit of script if uploading is allowed
            if (m_allowUploads)
            {
                html.AppendLine(
                    @"<script>
function selectedFileChanged(fileInput, urlPrefix)
{
 document.getElementById('uploadHdr').innerText = 'Uploading ' + fileInput.files[0].name + '...';
 // Need XMLHttpRequest to do the upload
 if (!window.XMLHttpRequest)
 {
 alert('Your browser does not support XMLHttpRequest. Please update your browser.');
 return;
 }
 // Hide the file selection controls while we upload
 var uploadControl = document.getElementById('uploader');
 if (uploadControl)
 {
 uploadControl.style.visibility = 'hidden';
 }
 // Build a URL for the request
 if (urlPrefix.lastIndexOf('/') != urlPrefix.length - 1)
 {
 urlPrefix += '/';
 }

 var uploadURL = urlPrefix + fileInput.files[0].name;
 // Create the service request object
 var req = new XMLHttpRequest();
 req.open('PUT', uploadURL);
 req.onreadystatechange = function()
 {
 document.getElementById('uploadHdr').innerText = 'Upload (request status == ' + req.status + ')';
 };
 req.send(fileInput.files[0]);
}
</script>
");
            }

            foreach (Dir422 directory in dir.GetDirs())
            {
                string path = GetHREF(dir, true) + "/" + directory.Name;
                string name = directory.Name;
                name = name.Replace("%20", " ");
                path = path.Replace("%20", " ");
                html.AppendFormat("<a href=\'{0}\'>{1}</a><br>", path, name);
            }
            html.Append("<br><br><h1>Files</h1>");
            foreach (File422 file in dir.GetFiles())
            {
                string path = GetHREF(dir, true) + "/" + file.Name;
                string name = file.Name;
                name = name.Replace("%20", " ");
                path = path.Replace("%20", " ");
                html.AppendFormat("<a href=\"{0}\">{1}</a><br>", path, name);
            }
            // If uploading is allowed, put the uploader at the bottom
            if (m_allowUploads)
            {
                html.Append(GetHREF(dir, true));
                html.AppendFormat(
                    "<hr><h3 id='uploadHdr'>Upload</h3><br>" +
                    "<input id=\"uploader\" type='file' " +
                    "onchange='selectedFileChanged(this,\"{0}\")' /><hr>",
                    GetHREF(dir, true));
            }

            return(html.ToString());
        }
Пример #17
0
        public void StdFSDirGetDirsTest()
        {
            IList <Dir422> dirs = root.GetDirs();

            Assert.AreEqual(2, dirs.Count);
        }
Пример #18
0
        private string BuildDirHTML(Dir422 directory)
        {
            StringBuilder foldersBuilder = new StringBuilder();
            StringBuilder filesBuilder   = new StringBuilder();

            var dirs  = directory.GetDirs();
            var files = directory.GetFiles();

            const string nodeTemplate = "<a href=\"" + _route + "{0}\">{1}</a><br>";
            string       path         = "";

            if (dirs.Count > 0)
            {
                path = BuildPath(directory);
                foldersBuilder.Append("<h1>Folders</h1>");
                foreach (Dir422 dir in dirs)
                {
                    string dirName = dir.Name.Replace("#", "%23");
                    foldersBuilder.Append(
                        String.Format(nodeTemplate,
                                      path + "/" + dirName, dir.Name)
                        );
                }
            }

            if (files.Count > 0)
            {
                path = BuildPath(directory);
                filesBuilder.Append("<h1>Files</h1>");
                foreach (File422 file in files)
                {
                    string fileName = file.Name.Replace("#", "%23");
                    filesBuilder.Append(
                        String.Format(nodeTemplate,
                                      path + "/" + fileName, file.Name)
                        );
                }
            }

            StringBuilder sb = new StringBuilder("<html>");

            if (_allowUploads)
            {
                sb.AppendLine(uploadJS);
            }

            if (files.Count == 0 && dirs.Count == 0)
            {
                sb.Append("<h1>Empty Directory.</h1>");
            }
            else
            {
                sb.AppendFormat("{0}{1}",
                                foldersBuilder.ToString(), filesBuilder.ToString());
            }

            if (_allowUploads)
            {
                sb.AppendFormat(uploadJS2, _route + BuildPath(directory)); //this second parameter is GetHREF in Evan's hw description
            }

            sb.Append("</html>");

            return(sb.ToString());
        }
Пример #19
0
        private string BuildDirHTML(Dir422 directory)
        {
            StringBuilder html = new StringBuilder("");

            // We'll need a bit of script if uploading is allowed
            if (m_allowUploads)
            {
                html.AppendLine(
                    @"<script>
                function selectedFileChanged(fileInput, urlPrefix) 
                {
                    document.getElementById('uploadHdr').innerText = 'Uploading ' + fileInput.files[0].name + '...';
                    
                    // Need XMLHttpRequest to do the upload 
                    if (!window.XMLHttpRequest) {
                        alert('Your browser does not support XMLHttpRequest. Please update your browser.');
                        return; 
                    }
                    
                    // Hide the file selection controls while we upload
                    var uploadControl = document.getElementById('uploader'); 
                    if (uploadControl) {
                        uploadControl.style.visibility = 'hidden'; 
                    }
                
                    // Build a URL for the request
                    if (urlPrefix.lastIndexOf('/') != urlPrefix.length - 1) {
                    urlPrefix += '/'; 
                    }
                
                    var uploadURL = urlPrefix + fileInput.files[0].name;
                    
                    // Create the service request object 
                    var req = new XMLHttpRequest(); 
                    req.open('PUT', uploadURL); 
                    req.onreadystatechange = function() {
                        document.getElementById('uploadHdr').innerText = 'Upload (request status == ' + req.status + ')'; 
                    };
                    req.send(fileInput.files[0]); 
                }
                </script> "
                    );
            }

            //Files
            String dirPath = "";
            Dir422 temp    = directory;

            while (temp.Parent != null)
            {
                dirPath = temp.Name + "/" + dirPath;
                temp    = temp.Parent;
            }
            dirPath = ServiceURI + "/" + dirPath;

            if (directory.GetFiles().Count > 0)
            {
                html.AppendLine("<h1 style=\"color:black;\">Files</h1>");
            }
            foreach (File422 file in directory.GetFiles())
            {
                //string name = PercentEncoding(file.Name);
                //string href = dirPath + name;
                string href = dirPath + file.Name;
                html.AppendFormat("<a href=\"{0}\">{1}</a>   <br>", href, file.Name);
            }

            //Directories
            //General Note: Don't forget percent encoding and decoding.
            if (directory.GetDirs().Count > 0)
            {
                html.AppendLine("<hr></hr><h1 style=\"color:black;\">Folders</h1>");
            }
            foreach (Dir422 d in directory.GetDirs())
            {
                //string name = PercentEncoding(d.Name);
                //string href = dirPath + name;
                string href = dirPath + d.Name;
                html.AppendFormat("<a href=\"{0}\">{1}</a>   <br>", href, d.Name);
            }

            // If uploading is allowed, put the uploader at the bottom
            if (m_allowUploads)
            {
                html.AppendFormat(
                    "<hr><h3 id='uploadHdr'>Upload</h3><br>" +
                    "<input id=\"uploader\" type='file' " + "onchange='selectedFileChanged(this,\"{0}\")' /><hr>",
                    GetHREF(directory));
            }
            html.Append("</html>");

            return(html.ToString());
        }
Пример #20
0
        string BuildDirHTML(Dir422 directory)
        {
            // Build an HTML file listing
            var sb = new StringBuilder("<html>");

            // We'll need a bit of script if uploading is allowed
            if (m_allowUploads)
            {
                sb.AppendLine(
                    @"<script>
          function selectedFileChanged(fileInput, urlPrefix)
          { 
            document.getElementById('uploadHdr').innerText = 'Uploading ' + fileInput.files[0].name + '...';
            
            // Need XMLHttpRequest to do the upload
            if (!window.XMLHttpRequest)
            { 
              alert('Your browser does not support XMLHttpRequest. Please update your browser.');
              return;
            }

            // Hide the file selection controls while we upload
            var uploadControl = document.getElementById('uploader');
            if (uploadControl)
            {
              uploadControl.style.visibility = 'hidden';
            }
    
            // Build a URL for the request
            if (urlPrefix.lastIndexOf('/') != urlPrefix.length - 1)
            {
              urlPrefix += '/';
            }
            var uploadURL = urlPrefix + fileInput.files[0].name;

            // Create the service request object
            var req = new XMLHttpRequest();
            req.open('PUT', uploadURL);
            req.onreadystatechange = function()
            {
              document.getElementById('uploadHdr').innerText = 'Upload (request status == ' + req.status + ')';
              // Un-comment the line below and comment-out the line above if you want the page to
              // refresh after the upload
              //location.reload();
            };
            req.send(fileInput.files[0]);
          }
          </script>
          ");
            }

            sb.Append("   <h1>Files</h1>");

            //Files first
            String dirPath = "";
            Dir422 temp    = directory;

            while (temp.Parent != null)
            {
                dirPath = temp.Name + "/" + dirPath;
                temp    = temp.Parent;
            }
            dirPath = ServiceURI + "/" + dirPath;

            var files = directory.GetFiles();

            foreach (File422 file in files)
            {
                string href = dirPath + file.Name;
                sb.AppendFormat("<a href=\"{0}\">{1}</a>   <br>", href, file.Name);
            }

            sb.Append("<h1>Folders</h1>");

            //General Note: Don't forget percent encoding and decoding.
            foreach (Dir422 dir1 in directory.GetDirs())
            {
                string href = dirPath + dir1.Name;
                sb.AppendFormat("<a href=\"{0}\">{1}</a>   <br>", href, dir1.Name);
            }

            // If uploading is allowed, put the uploader at the bottom
            if (m_allowUploads)
            {
                sb.AppendFormat(
                    "<hr><h3 id='uploadHdr'>Upload</h3><br>" +
                    "<input id=\"uploader\" type='file' " +
                    "onchange='selectedFileChanged(this,\"{0}\")' /><hr>", dirPath.TrimEnd('/'));
            }
            sb.Append("</html>");

            return(sb.ToString());
        }