473,417 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,417 software developers and data experts.

store files at my web host - how

How would I go about storing data files on my web host?

I have an Access database driven website and I would like to save files and
be able to download them. Can somebody point me in the right direction of
how I would go about doing that?

I am thinking about storing the locations of them in the database and the
physical files somewhere else. Not sure how to go about it though.

Thanks.


Nov 18 '05 #1
2 3176
Bit of a newb, here, so take my advice with a grain of salt, but:

Have a look for some file uploading tutorials - most of them will show you
how to upload and then save files to disk. You can grab filenames either
from the file input field or from user input via a textbox or something. You
can save the file to disk with that name, and then pass the name and path to
a database.

I'm doing something similar with product images, so I'll post a little of my
code - keep in mind it's probably not entirely best practice, and likely
poorly coded, but hopefully it'll start you in the right direction! ;)

============================

private void btnUpload_Click(object sender, System.EventArgs e)
{
if(fileImage.PostedFile != null &&
(fileImage.PostedFile.ContentType == "image/jpeg" ||
fileImage.PostedFile.ContentType == "image/pjpeg" ||
fileImage.PostedFile.ContentType == "image/gif" ||
fileImage.PostedFile.ContentType == "image/png"))
{

string fileName = fileImage.PostedFile.FileName;
char[] dirChars = new char[2] {'/','\\'};
fileName = fileName.Remove(0,fileName.LastIndexOfAny(dirChars ) + 1);

fileImage.PostedFile.SaveAs(Server.MapPath("..\\pr dimages") + "\\" +
fileName);

PopulatePage();
}

=====================

For this code I have a file input field turned into a server control named
'fileImage'. Next to it I have a button (not the 'browse' button) called
btnUpload that runs this method. I check to make sure a file has been posted
and it's a certain contenttype. Then I try to get the filename alone (maybe
not the best way to do it) and save it in a directory on the webserver. This
keeps the filename the same - it's probably better to let the user specify a
new one.

If you want, you could add code to take the filename you got here and add it
to a database. You can grab a bit of metadata as well from the PostedFile,
and store that too if necessary. I've done that in another method, to
associate images with products. So you could always grab your image paths
from the database. An alternative method might be, however, to do something
like this:

========

public string[] prodGetImageNames()
{
string path = HttpContext.Current.Server.MapPath("..\\prdimages" );
string[] filesTemp = Directory.GetFiles(path);
string[] fileNames = new string[filesTemp.Length];

for(int i=0; i<filesTemp.Length; i++)
{
fileNames[i] = Path.GetFileName(filesTemp[i]); //changes fullpath to
filename
}

return fileNames;
}

=========

This method looks into my products images directory, grabs all the
filenames, and uses them to populate a string array that I return as a
datasource to a dropdown list. It uses System.IO. I can guess at about 20
ways to code this better, but am not skilled enough to do it yet; but
hopefully it gives you an idea for a possibility. I don't know if it's
faster to grab the names from the database or from the filesystem, though..
probably DB?

Anyway, good luck!

-John

"Tim Zych" <tzych@noworms_earth_link.dott.net> wrote in message
news:u%****************@tk2msftngp13.phx.gbl...
How would I go about storing data files on my web host?

I have an Access database driven website and I would like to save files and be able to download them. Can somebody point me in the right direction of
how I would go about doing that?

I am thinking about storing the locations of them in the database and the
physical files somewhere else. Not sure how to go about it though.

Thanks.

Nov 18 '05 #2
Thanks John.

"John" <jc*****************@hotmail.com> wrote in message
news:p2*****************@news-server.bigpond.net.au...
Bit of a newb, here, so take my advice with a grain of salt, but:

Have a look for some file uploading tutorials - most of them will show you
how to upload and then save files to disk. You can grab filenames either
from the file input field or from user input via a textbox or something. You can save the file to disk with that name, and then pass the name and path to a database.

I'm doing something similar with product images, so I'll post a little of my code - keep in mind it's probably not entirely best practice, and likely
poorly coded, but hopefully it'll start you in the right direction! ;)

============================

private void btnUpload_Click(object sender, System.EventArgs e)
{
if(fileImage.PostedFile != null &&
(fileImage.PostedFile.ContentType == "image/jpeg" ||
fileImage.PostedFile.ContentType == "image/pjpeg" ||
fileImage.PostedFile.ContentType == "image/gif" ||
fileImage.PostedFile.ContentType == "image/png"))
{

string fileName = fileImage.PostedFile.FileName;
char[] dirChars = new char[2] {'/','\\'};
fileName = fileName.Remove(0,fileName.LastIndexOfAny(dirChars ) + 1);
fileImage.PostedFile.SaveAs(Server.MapPath("..\\pr dimages") + "\\" + fileName);

PopulatePage();
}

=====================

For this code I have a file input field turned into a server control named
'fileImage'. Next to it I have a button (not the 'browse' button) called
btnUpload that runs this method. I check to make sure a file has been posted and it's a certain contenttype. Then I try to get the filename alone (maybe not the best way to do it) and save it in a directory on the webserver. This keeps the filename the same - it's probably better to let the user specify a new one.

If you want, you could add code to take the filename you got here and add it to a database. You can grab a bit of metadata as well from the PostedFile,
and store that too if necessary. I've done that in another method, to
associate images with products. So you could always grab your image paths
from the database. An alternative method might be, however, to do something like this:

========

public string[] prodGetImageNames()
{
string path = HttpContext.Current.Server.MapPath("..\\prdimages" );
string[] filesTemp = Directory.GetFiles(path);
string[] fileNames = new string[filesTemp.Length];

for(int i=0; i<filesTemp.Length; i++)
{
fileNames[i] = Path.GetFileName(filesTemp[i]); //changes fullpath to filename
}

return fileNames;
}

=========

This method looks into my products images directory, grabs all the
filenames, and uses them to populate a string array that I return as a
datasource to a dropdown list. It uses System.IO. I can guess at about 20
ways to code this better, but am not skilled enough to do it yet; but
hopefully it gives you an idea for a possibility. I don't know if it's
faster to grab the names from the database or from the filesystem, though.. probably DB?

Anyway, good luck!

-John

"Tim Zych" <tzych@noworms_earth_link.dott.net> wrote in message
news:u%****************@tk2msftngp13.phx.gbl...
How would I go about storing data files on my web host?

I have an Access database driven website and I would like to save files

and
be able to download them. Can somebody point me in the right direction of how I would go about doing that?

I am thinking about storing the locations of them in the database and the physical files somewhere else. Not sure how to go about it though.

Thanks.


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Jaime Rios | last post by:
Hi, I created a COM AddIn for Word that performs the functions that it needs to, but I needed to add the ability for the toolbar created by the COM AddIn to remember it's last position and...
4
by: Mark | last post by:
I am developing a Web site and can't figure out how to store the project files on the Web server instead of my local hard drive. There must be a way, otherwise people wouldn't be able to...
4
by: RedHair | last post by:
I'd like to set up a file system for the ASP.NET 2.0 application to store user-uploaded files, since the members are more than 100,000 people, the basic requirements are as below: (1) The file...
0
by: metaperl | last post by:
A Comparison of Python Class Objects and Init Files for Program Configuration ============================================================================= Terrence Brannon bauhaus@metaperl.com...
1
by: =?Utf-8?B?TW9uaWNh?= | last post by:
Hi, An ASP.NET Web application was created in C# and you want to deploy it to a host server on the Internet. The application was configured with code-behind pages which are compiled in the build...
0
by: aym | last post by:
Hi everyone, I have about 20 domains on one host and I want to transfer my domains files to another host of course every domain name will be the same as it is, so how can I transfer my files from...
7
by: Giancarlo Bassi | last post by:
Please, what are here the 11 include files (found over the internet)? */mozzarella.c /* #include #include #include #include #include #include
8
by: pim | last post by:
Dear All, What I was wondering is how safe it is to store user_id or username or anything like that in session. I usualy store a bunch of info in a session so I do not need to search the...
9
by: =?Utf-8?B?U3RldmVuIFRhbmc=?= | last post by:
I want to download pfx from my asp.net server, add the pfx to client's X509Store as a trusted publisher, Is it possible? my func in aspx is like this: void InstallCertification() { try{...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.