help with 'given path's format is not supported'

I have 5 HtmlInputControls on my webform allowing the user to upload 0-5 documents. I want the Upload button to upload the documents BUT NOT SAVE them yet. I don't want the SaveAs method to run until final submit of the form. So I have two methods to handle this. The second method, SaveFile( ), is not working. I get error message: The given path's format is not supported. I'm brand new to and don't have a great grasp of the different classes involved with the FileUpload so I'm not sure if I'm using them correctly. Would appreciated someone looking over my two methods.


protected void UploadBtn_Click(object sender, EventArgs e)
    {   //this method called when user clicks the Upload button of the HtmlFileInput control this method works fine
        /* get the files that are in the uploaded collection. If there are 5 HtmlInputControls, does this mean
         that the collection consists of 5 object files?  Or does the collection only consist of the HtmlInputControls
        that were actually used by the user? The collection exists as long as the page exists.*/

        HttpFileCollection uploadFiles = Request.Files;
        //for however many files are in the collection...
        for (int i = 0; i < uploadFiles.Count; i++)
            // get the individual file from the files we got in the upload collection
            HttpPostedFile file = uploadFiles[i];
            //get the filename of the uploaded file
            string fileName = Path.GetFileName(file.FileName);

            /* if the filename isn't empty  - is this necessary because the collection consists of 5 items and
            we are checking which HtmlInputControls were actually used? */
            if(fileName.Trim() != "" )
                    //method to display the filename to the page for the user to see
                    ShowMessage(fileName, i);                                   
                catch (Exception ex)
                    //show the error message in the label
                    this.ShowMessage(" " + ex.Message, i);

    protected bool SaveFiles()
    { //this method called on final submit of the web form. It is NOT working
      bool successful = true;
      // for evey one of the files in the HttpFileCollect (gotten in the BtnUpload_click method
        for (int i = 0; i < Request.Files.Count; i++)
            // create a handler to use for reference as we iterate through the files
            HttpPostedFile file = Request.Files[i];
            //get the file name and set to a local variable to use in either section of try block
            string filename = Path.GetFileName(file.FileName).Trim();

            //if(file != null) //didn't make any difference
               // append a datetime stamp to the file name and save the file in the Uploads folder
               file.SaveAs(Server.MapPath("~/Uploads/") + filename + Convert.ToString(System.DateTime.Now));              
            catch (Exception ex)
               // Response.Write(filename + "<br />"); //doesn't work
               // this.ShowMessage(ex.Message, i); //error: The given path's format is not supported. 
                this.ShowMessage(filename, i);  //doesn't work
                successful = false;
      return false;       

3/28/2007 8:48:50 PM 93655 articles. 6 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 4

I think it's this line:   Convert.ToString(System.DateTime.Now));              

The time is being included which includes colons (12:34:56) which are illegal in a path name.

You could try:  System.DateTime.Now.ToString("yyyyMMdd");


Steve Wellens

My blog
3/28/2007 10:17:58 PM

I had already realized that my concatenation was wrong because it would have done this:

filename.docdatetimehere  when what I wanted was filenamedatetimehere.doc.

Still have same problem.  after 2 days on these file uploads, I've decided to not present the user with an Upload button and just handle the upload and saveas on the final submit. 


3/28/2007 10:35:30 PM
You do realize that the files will be uploaded regardless of what button was pressed? Even though you discrad them server side they are still uploaded to the server
3/28/2007 10:41:21 PM

Similar Artilces:

Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/ GranParadiso/3.0a1 From URL: Note to readers: Hendrix gives...

Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\ to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified, it calls t/uni/, that, in, (when the path separators are '\'), the $file is '..\lib\unicore\To\' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

Help with 'do until' ......... 'Loop'
Hello Everyone, I am writing a program to search for customers on a database.  I am having a bit of a problem with my do until ..... loop routines. I have posted the code below for you to look at and correct me. I am using VB on VS 2005 and Access Database. The end user will enter the customers name (Whole or part of ) in to a textbox and click the button 'Find', once the checks have been done to make sure there is something in the textbox it will then call this routine Search_Customer(ByVal Customer_Name).  The ByVal Customer_name will have the text...

Name: L Lachowsky Email: e2brutus_10atyahoodotcom Product: Firefox Summary: ''' Comments: why duddn this surprise me... I change default server from IE to Mozilla, and then i get error messages. well, shud I decide to not get on my computer with Mozilla..or shud I risk security breeches with IE....hmmm at least i can get on the internet with IE Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/2008120122 Firefox/3.0.5 From URL: Note to readers: Hendrix gives no expectation of a response to this fee...

Help! I cannot access the DataGrid's ItemTemplate's LinkButton's Text Atrribute 's Value!!!!!!!!!!!
I write a datagrid's ItemDataBound method as follows:   private void dgTable_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)  {   if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)   {    if(!isRole("Manager"))    {     LinkButton tmp = (LinkButton)e.Item.FindControl("lbPassed");     if(tmp.Text == "Passed")     {      ((LinkBu...

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

table_info('','','','%') cannot return any types
I was recently confirming table_info special cases and discovered the case for getting table_types cannot work. table_info('','','','%') should return a list of table types but it returns a list of empty strings instead: my @types = $h->tables('', '', '', '%'); print "all types:\n", join("xxx\n", @types), "\n"; # should output something like: # "dbo" # "INFORMATION_SCHEMA" # "sys" # and actually outputs: xxx xxx It seems to be down to the following ...

It's the fastest ''firefox'' i've ever had!!!:)
Name: Blagovest Email: blago_944atabvdotbg Product: Firefox Summary: It's the fastest ''firefox'' i've ever had!!!:) Comments: I's a great product!I'm really amazed! Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1 From URL: Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to see it. ...

Give access to non virtual folder through configuration entry? ERROR: <location> path attribute must be a relative virtual path. It cannot contain any of '?' ':' '\' '*' '"' '<' '>' or '|'.
I have a webpage running under a virtual directory that is mapped to d:/webapplication that produces an excel spreadsheet, the page calls a library object that generates a report and places it in a folder d:/attachments. This folder is not in the virtual directory. When I access the webpage i click a button and it attemps to return the created spreadsheet as a mim content type application/ However i getting redirected back to the login page of the application. Ive also noticed that the excel spreadsheet has not even been created at this location. So assuming this...

What's the difference between 'Build' and 'Publish'
Greetings....this subject might belong in one of the Visual Studio forums but it's so danged noob-sque.... I'm particularly confused by the 'Precompiled' term in the Publish operation. I'm interested in the path of least resistance between my VS project and my public IIS webserver. thx--steve...  Build means creating the assembly of the project ( .dll or .exe file) wich contains MSIL and a manifest file. When you publish your project u just produce the structure of your folder without producing a .dll file when you want to deploy your Web Project. ...

Hello. I'm using defferent 5.6.0's for Win32. I wonder wheter following behaviour is intentional or not: d:\>perl -e "print 'b'..'c'" bc d:\>perl -e "print 'b'..'a'" bcdefghijklmnopqrstuvwxyz I expected empty list in latter case, like in perl -e "print 'bb'..'a'" <!ENTITY Vadim REALLIFE "Vadim V.Konovalov, St.Petersburg, Russia"> &Vadim; On Wed, Sep 20, 2000 at 03:14:41PM +0400, Konovalov, Vadim wrote: > Hello. > > I'm using defferent 5.6.0'...

'or' or 'union'
Hello I was just wondering, in general what is better to use, an 'or' clause in a select or a 'union' to join two selects together. Do both statements create work tables? Many thanks Alex I think OR will be better than union. because suppose u have 3 tables and using OR u can join table a and table b and table c so each table will have only one read. but using union you will join table a and table b and in another query of union u will use table (a or b) and table c so ur one read is more in union . Ramdas Alex Cheung wrote: > Hello > >...

'IN' Clause or 'OR'
Hello, [1]: select * from TABLEA where COL1 IN('value1','value2''valu3'....) [2]:select * from TABLEA where COL1 = 'value1' OR COL1= 'value2' OR COL1='valu3'. TABLEA is a huge table and it has non-clustered index on COL1. Among the above 2 queries, which query will give me the better performance or fast response and WHY? What is the difference between 'IN' and 'OR' clauses as for as Sybase Optimization is concerned. Which is the better one to be used on huge tables. Thanks. Mac An IN list is treated as a series of OR clauses. There's no diff between the two as far as the optimizer is concerned. Eric Miner Sr. engineer Optimizer Group Ma wrote: > Hello, > > [1]: select * from TABLEA where COL1 IN('value1','value2''valu3'....) > > [2]:select * from TABLEA where COL1 = 'value1' OR COL1= 'value2' OR > COL1='valu3'. > > TABLEA is a huge table and it has non-clustered index on COL1. Among the > above 2 queries, which query will give me the better performance or fast > response and WHY? > > What is the difference between 'IN' and 'OR' clauses as for as Sybase > Optimization is concerned. Which is the better one to be used on huge > tables. > > Thanks. > Mac ...

'System.Web.HttpRequest' does not contain a definition for 'form'
Hello all. .NET 2.0 newbie here.... What I'm trying to do is learn how to use the LoadVars() in actionscript. Here is the .NET / C#/ html code  1 <form id="form1" runat="server"> 2 <div> 3 <% 4 if (Request.form("userName") == "Cameron") 5 { 6 Response.Write("&aspvar=it is You!"); 7 } 8 else 9 { 10 Response.Write("&aspvar=you are not Cameron&"); 11 } 12 13 %> ...

Use 'Credentials' in 'Authentication' in file 'Web.Config'
Why 'LoginUrl' is not recoganized by ASP.NET when I use in authentication mode 'Form'? Before VS.NET in which .NET1.0 is predefined was installed,I had installed .NET1.1 seperatedly. However,the error message indicates configuration error is just from .NET1.0. Therefore,is that 'LoginUrl' only accepted in .NET1.1? 'loginUrl' should work in both versions. Please note the authentication mode should be "Forms", not "Form". What is the error message you are getting? Thanks, Laura.This posting is provided "AS IS" with no warranties, and confers no rights. Yes,I...

'Value' should be between 'minimum' and 'maximum'.
I'm attempting to invoke with parameters:  Dim thing2 As New mydelsubPBStep(AddressOf pbStep) Me.Invoke(thing2, "setMax", dt.Rows.Count)      <---- this is where the error occurs   the delegate looks like this: Private Delegate Sub mydelsubPBStep(ByVal mode As String, ByVal value As Integer)   the function it's calling looks like this:Private Sub pbStep(ByVal mode As String, ByVal value As Integer) Select Case mode.ToLower Case "clear" ProgressBar1.Value = 0 Case "step" ProgressBar1.PerformStep() L...

'To', 'CC', & 'BCC'
Name: Dick Tracy Email: philipdottracyatoptusnetdotcomdotau Product: Thunderbird Summary: 'To', 'CC', & 'BCC' Comments: I have just started using Thunderbird and while I find it quite excellent- I suggest having a button to add addressees to 'BCC' as well. Currently each 'BCC' addressee has to be selected manually. I send e-mail to quite a number of people at a time and I do not wish to readily spread others addresses easily. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070725 Firefox/2.0....

EXEC sp_msforeachtable 'sp_spaceused ''?'''
What does the following SQL code mean?  EXEC sp_msforeachtable 'sp_spaceused ''?'''Johan TheunissenMCPD, MCSE, MCTS BizTalk 2006==============================Please mark the most helpful reply/replies as "Answer". JohanNL:sp_msforeachtable This is the name of the SP that resides in the master database.  This SP executes one or more commands for a table. JohanNL:sp_spaceused This is the command that you want to run for each of the tables residing in your current database.  As you might have understood so far, that this is again a...

Cannot wrap 'Element''s 'addEventListener' method
On Firefox ( v2 and v3, and probably the earlier versions) it does not seem possible, at least under some circumstances, to extend the 'addEventListener' prototype of the 'Element' object in JS or to extend the prototype of its inheriting objects. This forces JavaScript frameworks that would like to leverage Element's prototype for this (or its inheriting objects) to treat Firefox like IE in this case -- they have to perform an extension operation on every single individual dom element that they need framework-style behavior from. That's a significant performan...

The value's length for key 'data source' exceeds it's limit of '128'.
Hii, When I tried to bind dropdownlist to database by declaring connection string in the code behind file I am getting this error: The value's length for key 'data source' exceeds it's limit of '128'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: The value's length for key 'data source' exceeds it's limit of '128'.Source Error: An...

Help 'C' Guru's
In my studies of 'C' I've been trying to tweek a program to add an if -else statement and get away from goto statement. The one I have chosen doesn't seem to work and I can't figure out why...maybe you guys can see something I missed. The if-else statement near the bottom is the culprit. I can get the program to run the if part but, fails on the else part. Its as though that part of the code isn't being read if "if" is false. I've tried it with if(drop!=BOTTOM_ROW) with conditions if an else examines swaped around. if(drop<BOTTOM_ROW) with conditions if an else examines swaped around. And with what is currently in the code to no availl...any help would be appreciated. NOTE: The program compiles without error and runs everything but the else statement. Here is the source code #include <stdio.h> #include <stdlib.h> #include <dos.h> #include <conio.h> #define VIDEO 0x10 //Video interrupt #define COLS 80 //Screen width #define ROWS 25 //Screen rows #define BOTTOM_ROW 24 //Bottom row #define CENTER_COL 39 //Center colomn #define BOMB 162 //Bomb character #define PAUSE 3000000 //Pause time (0 - 16,000,000) void cls(void); void locate(int col,int row); int main() { int drop; unsigned long p; cls(); locate(CENTER_COL-3,BOTTOM_ROW); printf("PLANET BOB"); locate(0,0); prin...

What's magical about chdir('path')?
I'm stupmed. lib/File/Find/t/find.t is failing with: 1..78 Can't cd to []/pteerslt/path[--] at ../lib/File/ line 824. %RMS-F-DIR, error in directory name Somehow it made it's way into UTL$DISK:[UTL]. So I decided to override chdir() using *CORE::GLOBAL::chdir and trace at what point it flies off: 1..78 # cwd: USER1:[SCHWERN.SRC.BLEADPERL.T] # chdir: run from ../lib/File/ at 740 # newcwd: USER1:[SCHWERN.SRC.BLEADPERL.T.RUN] # cwd: USER1:[SCHWERN.SRC.BLEADPERL.T.RUN] # chdir: [-] from ../lib/File/ at 824 # newcwd: USER1:[SCHWERN...

How to Dist Between 'Web Forms' and 'HTML' Controls in VS 2005 IDE
I am using ASP.NET 2.  In books and articles, authors refer to and distinguish between 'Web' controls and 'HTML' controls.In the actual Vis Studio IDE toolbox for web forms,  I have one list of controls called 'Standard' containing controls like 'Button' etc. There is also a list labelled 'HTML'  with things like 'INPUT (button)' . There are a few other lists, but none labelled 'Web'. Where are the 'Web' controls found and what are they called in the IDE?  Same for the 'HTML' controls.   I see references in books to 'HTML' controls called 'TextBox', but I d...

Web resources about - help with 'given path's format is not supported' -

Resources last updated: 3/24/2016 9:19:36 AM