Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stream path not supported
Message
De
11/03/2009 13:13:41
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Application:
Desktop
Divers
Thread ID:
01387152
Message ID:
01387165
Vues:
63
>>Hi all,
>>
>>I am trying to use a FileStream to write out a record. I had this working but today out of the blue with a different path it won't work. I keep getting "The given path's format is not supported". What is wrong with these paths I have tried.
>>
>>
>>FileStream stream = null;
>>try
>>{
>>     stream = File.Create(saveName);
>>     XmlSerializer xml = new XmlSerializer(record.GetType());
>>     xml.Serialize(stream, record);
>>}
>>
>>where "saveName" is equal to
>>"C:\\DevelopCSharp\\Pacifica.Tracker\\TrackerClient\\Database\\SpotQueue\\Spot_3-11-2009(15:49:59).xml"
>>or since I thought the Pacifica.Tracker with a period in it might be the problem
>>"C:\\DevelopCSharp\\TrackerClientTemp\\Database\SpotQueue\\Spot_3-11-2009(15:49:59).xml"
>>
>>None of this works. The file name with the time in parens was working for weeks, the only thing that changed was the app directory.
>>
>>Any ideas?
>>Tim
>
>Can you post the code where you assing the path to the string variable saveName?
>are you using something like this
>
>string saveName = @"C:\DevelopCSharp\TrackerClientTemp\Database\SpotQueue\Spot_3-11-2009(15:49:59).xml";
>
>Then you don't have to mess with the double slash
>If you are not using the @ then you do have to use the double slash and I noticed that you are missing a double slash in your path.
>
>Also take a look at the System.IO.Path class, which is very useful when working with paths and filenames.

The missing double slash was a typo when I posted. I am using the @ so the double slashes are added for me and the value of saveName is while in debug mode where I copied it from. I have found the issue to be with the file name as I changed it and it no longer was a problem. I don't undersand why though since I have created many records using that same file name creating code. The exception thrown is the "NotSupportedException" of File.Create(string) method.
string saveName = this.FileQueueDataPath + @"\Spot_" + fileID + ".xml";
FileStream stream = null;
try
{
     stream = File.Create(saveName);
     // everthing else left out
}

public string FileQueueDataPath
{
     get
     {
          if (_queueDataPath == "")
          {					
               _queueDataPath = TrackerSettings.Instance.AppDirectory + TrackerSettings.Instance.QueueDirectory;
          }
          return _queueDataPath;
     }
}

Settings File contains:
public string AppDirectory		= @"C:\DevelopCSharp\TrackerClientTemp";
public string QueueDirectory		= @"\Database\SpotQueue";

public string CreateFileID()
{
    DateTime now = DateTime.Now;
    if (TrackerSettings.Instance.UseUtcFileId)
        now = now.ToUniversalTime();

    string fileID = now.Month.ToString() + "-" + now.Day.ToString() + "-" + now.Year.ToString() + "(";
    fileID += now.Hour.ToString() + ":" + now.Minute.ToString() + ":" + now.Second.ToString() + ")";

    return fileID;
}
I am checking out System.IO.Path class now
Thanks Einar,
Tim
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform