How to get list of folders from a website - c#

how can i get a list of folders from a website?
Namely I wrote a program that take a URL
And give a list of folders from the website.
I try
Directory.GetDirectories(myURL)
but it not work.

Generally, you will have to have the server run some code to get the list of directories. The client does not have access to the filesystem of the web server, and even using FTP or WebDAV the scope of what can be seen by the client will be limited.

The easiest way would be to create a folders.txt file in every directory on your web server with the name of all child directories. Then use your favorite HTTP API to download the file and parse its contents.
As for websites that are beyond your control: you can't. However you can check if you have access to a folder with a specific name. That should give you some ideas.

You can't directly access the file system on the web server (a .NET security feature). You can however do this when you're running locally (under localhost), but I understand that's not the point. If you're talking about submitting an URL that you don't own, then typically, no, that's not possible.

Related

SharePoint REST API: How to download List XML visible in browser to temp file C#

I have been looking at exporting data from a company SharePoint site using C# written in VS Express 2013. First, a caveat - I'm new to web based APIs (Soap or REST) and SharePoint, so apologies if my question is prosaically easy to answer/ badly worded. Pretty much all of my previous work has been with files local to the machine or on a similarly local company network that can be accessed in the same way.
My aim - download a list from one site, do stuff to it on the client machine and then re-upload it to a different SharePoint site.
I have tried using the Soap API (Client object model) but I am encountering a variety of access and permissions issues. So I switched to the REST API, and have now managed to get the list data into XML within my browser. But I don't really want it in my browser - I want to access it programmatically, and write selected data from the list into a local file (using System.IO.Path.GetTempPath() to find the temporary folder), without browser windows popping up (except to allow the user to log in to establish an authorized context with the server). There has to be some trivially easy way of saving the XML data to my temporary file without needing a browser open, but I haven't been able to find it.
My REST query is like the following:
https://sk.someSharePointSite/sites/subsection/_vti_bin/ListData.svc/AList
I would suggest you should use Sharepoint client object model for downloading/uploading files to sharepoint.
If there is anything specific you can't do with CSOM then use REST API.
You can check the code details here:
http://msdn.microsoft.com/en-us/library/ee956524%28office.14%29.aspx

Open local directory from ASP.NET MVC 3 Intranet application

I would like to know if it is possible to open a directory from intranet MVC application ? I have been searching about it but i don't found anything.
I tried to open from javascript using window.open('url') but i get unauthorized access.
Thanks,
Tiago MourĂ£o
IMPOSSIBLE !!!
web browsers does not have allow web pages to access to disk drives.
web pages only can read/write cookies.
FileUpload control allow access to the files, only with user action(scripts no allowed).
I found a way to do resolve this problem. If you create a background process using Process.Start('location'), the application opens directory folder.
Tips:
Process.Start() generally used in windows application and if used in
web applications, a process will start on server(not on user agent
that run current page).
you get unauthorized access error, because of IUser has limited
access ...
1) Web Applications can read/write any file and folders on server side with assigning permission.
2) WebApplication with Some sideway can access to file & folders in web pages (client side) !!!
with JavaScripts:
Write a browser add-on with requested functionality, then install on
user agent(browser).
now with call method/function in add-on, you can do the operations
that does not allowed with JavaScript & etc.
with VBScript(Obsoleted) that run/supported only in MsIE:
can using FileSystemObject to full access files and folders.
can using CreateObject to create instance of each object in OS and
working with it.
Finally my answer is IMPOSSIBLE.

Shared folder path on aspx form

I have some files in a shared location/folder. I need to provide a link/path on a webpage. If an user click on the link, user should be able to view the file.
I am using asp.net with C# (VS2010)
Is the above requirement is possible ?
If yes please help me in enabling this feature.
Thank you in advance
It should be possible using something like file://server/share/path/to/file.txt. Firefox is a lot more tolerant of encoding of characters in filenames than IE, so you may need to use Server.UrlEncode on the file path.
What I would do is to write an ASHX Generic Handler where you pass the requested file name as an URL parameter and that ASHX handler actually fetches the file for you, sends it to the browser.
This has these benefits in my opinion:
It uses the HTTP protocol, not the FILE protocol.
You are keeping internal structures internal, without exposing them to the visitors.
You can implement access rights and other things since the files are streamed through your handler, and are not directly delivered by the web server (IIS).
If NTFS security permissions are an issue you might use impersonation for fetching the files from your shared folder location. I've written a small impersonator class some years ago to simplify this task.

Passing file data between Administration app and Web site app

We have two separate web applications for a site: One for the site itself, and one for the cms/administration side. I'm not sure why the original developer designed it this way, but whatever.
I am tasked with adding some functionality to the administration side that uploads files. These files then need to exist within the folder structure of the actual site. I was thinking I might have to write a web service that sits on the actual site that accepts the file bytes and file name from a call within the administration site, and creates the file in the correct folder, but I was wondering if anyone had any ideas about a cleaner way to accomplish the same thing.
In general, how would you tackle a scenario where you upload a file on one site, and send it to the directory structure in another?
Thanks in advance!
The solution I ended up going with is to store the full file path to the other site in the web.config. It's not the most elegant solution, but it works and I'm mildly happy with it since it is easily maintainable across dev/staging/production.
You could create a Windows Service to transfer the uploaded files from one folder to another.
After a file is uploaded on the admin site, the windows service moves the file over to the correct location on the other site. You just need to decide how to communicate with the service - you could add details about the uploaded file to a message queue that the service monitors or perhaps you windows service might just watch the upload folder for any new files.

Subdomain Hosting Issue with Disk Access (C#/ASP.NET 3.5)

This isn't a very complicated scenario really, but as I start to type out the problem I'm realizing how convoluted it can become textually. Let me try and be very clear:
First, the set up...
I have a C#/ASP.NET web application that is publicly facing on my main domain (www), let's call it www.mysite.com. Nothing fancy, just a front-end that connects to SQL to display records.
Then, I have a second C#/ASP.NET web application that is secured using forms authentication running on a subdomain, let's call it admin.mysite.com. This is a very light-weight CMS system to administer the public site.
Now, the problem...
Both of these sites run fine for basic tasks, however, my problem arises when I try to gain access to the file system for uploading. My webhost requires subdomains to run as a virtual directories under the main application in IIS (so the subdomains actually resolve/re-direct to www.mysite.com/admin when you type in admin.mysite.com), but because of this I am unable to write to my website root from the subfolder.
Let me explain a little more...
The CMS system (running as a virtual directory) gives the admin the ability to upload photos for display on the main site, the target folder of which is www.mysite.com/images - when attempting disk access from the root app, I am able to write to the virtual directory, but cannot do the opposite -- that is, write to the root from the virtual directory, getting security violations. If I can only upload to the /admin/ virtual directory, the entire point is moot because it's a secured folder that the public can't see!
The only solution I can think of is to upload the files to the /admin/ virtual directory, then call a URL in the root that moves files from /admin/ back to the root, but that is entirely ghetto.
I hope this post makes sense. Anyone else experience anything like this? The bottom line is that it seems virtual directories ONLY have access to themselves, and not their parent directories, no matter what credentials are used.
Thanks!
Somewhat unrelated to your question.
GoDaddy is not a great host due to things like you have stated. I recently went on the search for a host and wholeheartedly recommend JodoHost.com.
Some post I wrote on the matter:
http://www.ocdprogrammer.com/post/2009/12/16/The-search-for-a-web-host.aspx
http://www.ocdprogrammer.com/post/2010/01/03/JODOHostcom.aspx
However, the behavior you are seeing seems very normal to me. A sub domain not being able to access the root domain. Though with a dedicated server you could overcome this, but one of the drawbacks of a shared host.
In that case, I think I would consider using a database.
Here's how I would do it:
The files are uploaded into the /admin directory
The admin app writes the URL of the file into the database that it shares with the root app
The root app loads the URL from the database and uses it to point to the file.
I think that is the best way to approach it, under such circumstances.
You could put a webservice in your root domain "www.yoursite.com" that will receive a stream and will save this stream to disk as file. (this webservice could receive three parameters: the stream, the name of the desireed file on disk, and eventually the destination folder for the file so it will be a multi-purpose write file system)
Later, in your subdomain "subdomain.yoursite.com" you could consume the webservice (when you
upload a file, convert to stream, and send it to the webservice hosted in the root site with
appropiate parameters).

Categories