Jump to content

load file address??

- - - - -

  • Please log in to reply
4 replies to this topic

#1
PutchPT

PutchPT

    Newbie

  • Members
  • Pip
  • 2 posts
Hi...

I'm trying to get a file address that i stored "manually" in an SQL server database using c#, i stored in the database the string "c:\projects\vids\simpsonslidetector.flv" and when i try to retrive, it ignores everything except "simpsonslidetector"... this is used as webservice, the webservice receives an int so it can match with a certain id in the table and when finds that id, returns the string (in this case not the whole string, in other cases with "simplier" strings it return well):

the table name on the database is 'info' and as 3 colums: id(int), name(nvarchar(100)), address(nvarchar(100))...what type of data should i use for the address?

also i have other methods that connect to the database to return a value or list of values, and goes fine, the only problem is the address string (i think the cause of not getting the result i want, is because, for some reason the reader does not receive the formatted string stored in the database ("c:\projects\vids\simpsonslidetector.flv")).

this is the code i use to retrieve the string:


[WebMethod]

    public String getAddressByID(Int32 id)

    {

        String strReader = "";

        SqlConnection conn = new SqlConnection(strCon);

        conn.Open();

        String readCmd = "SELECT address FROM info WHERE id = " + id.ToString();

        SqlCommand cmd = new SqlCommand(readCmd, conn);

        strReader = (String)cmd.ExecuteScalar();

        conn.Close();

        if (strReader == null)

        {

            return "No Result";

        }

        else

        {

            return strReader;

        }

    }


#2
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 403 posts
Try using

("c:\\projects\\vids\\simpsonslidetector.flv"))

OR

("c:'\'projects'\'vids'\'simpsonslidetector.flv"))

#3
PutchPT

PutchPT

    Newbie

  • Members
  • Pip
  • 2 posts
"found" the problem, it as nothing to do with the database or the c# code, but with the browser or with the server (my computer)... what happened!? the browser showed the last record after i changed the value in the database, for example:
1a- in the first time i had the information in the column with the string filename;
1b- launched the webservice, invoked the service and the result was correct
2a- and then i changed the string to filenameXPTO
2b- launched the webservice, invoked the service and guest what, the result was filena instead of filenameXPTO
3a- so i closed the server (ASP.NET Development Server) and the bowser, and cleaned the cookies and other information using CCleaner program
3b- then launched the webservice again without changing anything in the database, and the result was filenameXPTO
3c- then i did the same procedure but this changed the string to c:\projects\vids\simpsonslidetector.flv , and the return result is OK...

so, if anyone as the same problem try to clean the browsers cookies and restart the server, and test again (i was using firefox v4.0 bowser)...

Murali, thanks for your answer, and also do you know how to insert a string that as a relative path to the project itself, instead of using c:\projects\vids\simpsonslidetector.flv, using somthing like (IN HERE GOES THE FOLDER O THE PROJECT, THAT THE SYSTEM DETERMINES)\vids\simpsonslidetector.flv, so it can be teleported to any plataform...THANKS

cheers, PutchPT

#4
fayyazlodhi

fayyazlodhi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 403 posts
It used to be some thing like

System.Configuration.ConfigurationManager. AppSettings["whatever"]


ConfigurationSettings.AppSettings Property (System.Configuration)

#5
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts

fayyazlodhi said:

It used to be some thing like

System.Configuration.ConfigurationManager. AppSettings["whatever"]


it would be exactly like that so long as you reference the System.Configuration assembly from the GAC




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users