Using var in c#

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?
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
Код:
var path = project.Variables["path"].Value;
 
  • Спасибо
Реакции: Mankush

Mankush

Client
Регистрация
31.10.2011
Сообщения
189
Благодарностей
17
Баллы
28
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?
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
you use I instead of i
Код:
instance.SaveCookie("path");
 

Mankush

Client
Регистрация
31.10.2011
Сообщения
189
Благодарностей
17
Баллы
28
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?
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
Try this
Код:
instance.ActiveTab.Navigate("http://google.com/");
instance.ActiveTab.WaitDownloading();
// get cookie by domain
return instance.GetCookie("google.com", true);
 

Mankush

Client
Регистрация
31.10.2011
Сообщения
189
Благодарностей
17
Баллы
28
Very long string...
Then - just save the text in a file? is that the cookie?
 

rostonix

Известная личность
Регистрация
23.12.2011
Сообщения
29 067
Благодарностей
5 707
Баллы
113
yes
 
  • Спасибо
Реакции: Mankush

Mankush

Client
Регистрация
31.10.2011
Сообщения
189
Благодарностей
17
Баллы
28
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?
 

Mankush

Client
Регистрация
31.10.2011
Сообщения
189
Благодарностей
17
Баллы
28
Restarted and now it will only load another cookie (the third one) - and will not change it. I think it`s a bug(?)
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 774
Благодарностей
1 185
Баллы
113
Код:
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

Mankush

Client
Регистрация
31.10.2011
Сообщения
189
Благодарностей
17
Баллы
28
You are the best! thank you. now it`s all working : )
 

lokiys

Moderator
Регистрация
01.02.2012
Сообщения
4 774
Благодарностей
1 185
Баллы
113

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