For uploading a file to the hosting server you can get the physical path of
then append the rest of the folder path to this physical root folder. So lets
information, since the file is uploaded by the ASP.net application. All you
would need to do is to get read/write permissions for the ASPNET system user.
"patrick_a" wrote:
> Hello,
> I am deploying an ASP.net application written in C# to a hosting server
> where I have limited privileges. I know how to do image file uploads if I'm
> doing them with a path involving C:\ but what path do I use when I don't know
> that information. Do I set up a folder relative to my application folder in
> the www directory (ie. www/myapplication/uploads )and then save the image to
> it with a relative path like uploads/myimage.jpg or as an absolute path like
>
www.mysite.com/myapplication/uploads ? How can I authenticate a user before
> they can upload to the folder - do I create a user on the server with the
> upload folder as their root directory and then somehow pass the username and
> password in a string to be authenticated? Here is what the code looks like .
> Thanks for any help you can give me.
>
>
> protected System.Web.UI.HtmlControls.HtmlInputFile uploadPhoto;
> protected System.IO.Stream stream1;
>
>
> string strUploadDirectory = "uploads/"; //I need to know this directory
> path.
> string strUserName;
> string strFileName;
> string strPhotoTitle1;
> string strFileAndDirectory;
> long lMaxFileSize = 150000;
>
> strUserName=User.Identity.Name;
> strFileName=uploadPhoto.PostedFile.FileName.Trim();
>
> strFileName=Path.GetFileName(strFileName);
>
> if(strFileName!="")
> {
> //test for file size
> if ((uploadPhoto.PostedFile.ContentLength <= lMaxFileSize) &&
> (uploadPhoto.PostedFile.ContentLength > 0))
>
> { //create a unique name for the file
> strFileAndDirectory=strUploadDirectory + strUserName + strFileName;
> FileInfo fileinfo1 = new FileInfo(strFileAndDirectory);
>
> if (fileinfo1.Exists)//if file exists delete it
>
> {
> fileinfo1.Delete();
> }
> try
> { // load the uploaded file into a stream
> stream1 = uploadPhoto.PostedFile.InputStream;
>
> // this generates a handled error if file is not an image
> image1 = System.Drawing.Image.FromStream(stream1);
>
> // save image to upload directory
> image1.Save(strUploadDirectory + strUserName + strFileName);
> }
> catch
> {
> strFileName="no_image.jpg";
> }
> }
> else
> {
> strFileName="no_image.jpg";
> }
>
> }
> else
> {
> strFileName="no_image.jpg";
> }