Showing posts with label path. Show all posts
Showing posts with label path. Show all posts

Wednesday, March 28, 2012

System.IO.Directory.GetFiles(path, searchPattern)

Hi

I don't know if this is the right place to put this post but I didn't found anywhere else.

The thing is that I'm getting files in a directory but I would like to pick only four types of files: .wmv, .avi, .mpeg and .mpg. I know that the search pattern works but I can only search for one type of file. Can extend the search to look for all 4 types?

Thx

It seems that there is no direct way to do this, really strange. Maybe you can get all files under the directory, and then use regular expression to get files of these types?

Hi

Thx for the reply. I already thought of that. I know it works cause I tried it. I just wanted another way to optimize unnecessary code. But thanks anyway lori_Jay

System.io.File

When using the File object how do you now whether the path you are putting, is the path of a file on the server or the path of a file on the client machine.

I want to transfer a file from the client machine to the server, does anyone know if the File object is suited for this?I guess the real question there is where did you get the path from.

If the path came from the Posted File - then it is most likely the file path / name from the client not and is not valid for saving on the server
What do you mean when you say where the path came from, what if i hard code a file path to be e.g c:/intepub/newfolder/file.txt

If i put that path into a file object, would that look at c: on the server or client?
It's always a Path on your server or another machine in your network, over which you (or rather the ASPNET worker process or some other user you let the worker process impersonate) have rights to access.

The only time you handle a client path, is when someone has uploaded a file to your server.
Ok, but thats what i want to do using asp.net, i want to allow users to upload a file from their machine to the server. I have done this successfully using Java, but wanted to know if its possible using .net
It's extremely easy using .Net. One line of code will suffice in this very simple scenario:


<%@. Page Language="VB" %>
<%@. import Namespace="System.IO" %>
<script runat="server">
Sub Button_Click( obj As Object, evnt As EventArgs )
inpFileName.PostedFile.SaveAs( Server.MapPath("") & Path.GetFileName(inpFileName.PostedFile.FileName) )
End Sub
</script>
<html>
<head>
<title>Upload file</title>
</head>
<body>
<form enctype="multipart/form-data" runat="Server">
<input id="inpFileName" type="file" runat="Server" /><br>
<asp:Button id="btnFileUp" onclick="Button_Click" Runat="Server" Text="Upload file" /></form>
</body>
</html>

This will save an uploaded file to the root of your web application. Remember to grant rights to write to the physical folder for the ASPNET account. By default the max file size to be uploaded using .Net is set to 4 mb (4096 kb). If you need to up this size, you set it in your application's Web.config file using:

<httpRuntime maxRequestLength="<size in kb you wish to allow>" />

Thanks very much

System.IO.Path.GetTempFileName

Hi,
System.IO.Path.GetTempFileName( ) is supposed to create a temporary file and give us the path to the created file.
By default, where does this temp file get created? C:\Temp, C:\WinNT ?
Bcos right now this fails and error we get is "Access denied". But we dont know which folder's permissions to change as we dont know where this temp file is supposed to get created.

It will be in the ASPNET user's Temp Directory. For example, on mine:
C:\Documents and Settings\ComputerName\ASPNET\Local Settings\Temp


You are right ! I just found that out by using

tempPathString = Path.GetTempPath()
Thanks !


correctomundo!!
I know this is an old post, but System.IO.Path.GetTempPath() only puts stuff in the ASPNET user directory when the app runs on XP Pro. That is fine for development, but when the app is deployed to a Windows 2003 server the method returns C:\Windows\Temp. Calling GetTempFileName() creates a temp file there. Surely, it isn't safe or a best practice to write to the Windows directory, is it?

System.IO.StreamWriter -- Access to path is denied

Hi, I am trying to use the System.IO.StreamWriter to write to a file, and am getting an error that I have to set permissions for doing this in IIS -- I don't remember how to do this. Does anyone know how?

(Win XP Pro)


System.IO.StreamWriter writer = new System.IO.StreamWriter(@dotnet.itags.org."C:\NetApplicationTest",true);
Hi, u need to add aspNet User to the folder u trying to accessing and give the account have the permission to write/read it in the folder or file.

If u cant see any security tab on ur folder option, do tis below in any folder:
Tools>Folder Options>View>uncheck this "use simple file sharing(Recommended)"

then go to ur file's folder , note: folder
right click then properties> Security>Add > Advance> Find now>
Then u select ASPNET and add it, and set ASPNET to full control.

Hope tis help
life's Ng
beauty, thanks very much! -- I guess that I should study some XP Admin stuff... thanks 'gain ..