Using var in c#

  • Автор темы Автор темы Mankush
  • Дата начала Дата начала

Mankush

Client
Регистрация
31.10.2011
Сообщения
189
Реакции
17
Баллы
28
I`m trying to save cookie to a path which is stored in variable (I read the var from a table)
I tried the following code:

var path = "{-Variable.path-}";
instance.SaveCookie("path").txt;

Nothing happens.
Any ideas how should I write this code?
 
Код:
Развернуть Свернуть Копировать
var path = project.Variables["path"].Value;
 
  • Спасибо
Реакции: Mankush
I tried this code:
var path = project.Variables["path"].Value;
Instance.SaveCookie("path");

And got:
"An object reference is required for the non-static field, method, or property 'ZennoLab.CommandCenter.Instance.SaveCookie(String)' ".[Row: 2; Column:1]
What am I doing wrong?
 
you use I instead of i
Код:
Развернуть Свернуть Копировать
instance.SaveCookie("path");
 
Now it works fine (the c# code)
But no file is saved in the designated path...
I even tried once with "\" and once with "/" for the path slashes
Any ideas?
 
Try this
Код:
Развернуть Свернуть Копировать
instance.ActiveTab.Navigate("http://google.com/");
instance.ActiveTab.WaitDownloading();
// get cookie by domain
return instance.GetCookie("google.com", true);
 
Very long string...
Then - just save the text in a file? is that the cookie?
 
yes
 
  • Спасибо
Реакции: Mankush
I have saved several cookies. now when I try to load each one of them - it will only load the first cookie that I saved, though the var "path" is different every time.
I`m using this code:
var path = project.Variables["path"].Value;
instance.LoadCookie("path");

What am I doing wrong?
 
Restarted and now it will only load another cookie (the third one) - and will not change it. I think it`s a bug(?)
 
Код:
Развернуть Свернуть Копировать
string path = project.Variables["cookiePath"].Value;
instance.SaveCookie(path);

this is how you should save cookies...
Where path is whatever path you need.

Or you can build up path in c#
Example:

Код:
Развернуть Свернуть Копировать
string path = project.Directory + @"\Cookies\" + GoogleCookies + ".txt";

And path in this case will look like: {-Project.Directory-}Cookies\GoogleCookies.txt

With load cookies everything is that same, except this line:

instance.LoadCookie(path);

You got error because you using variable in quotes.
Variables should be used without quotes.

Cheers
 
  • Спасибо
Реакции: Mankush
You are the best! thank you. now it`s all working : )
 

Кто просматривает тему: (Всего: 0, Пользователи: 0, Гости: 0)