Section title formatting also in the toc
Here is a solution. I will try to explain if needed.
\documentclass{article}
\usepackage{xcolor}
\newenvironment{myenv}%
{\color{red}%
\addtocontents{toc}{\protect\begin{mytocenv}}}%
{\addtocontents{toc}{\protect\end{mytocenv}}}
\makeatletter
\let\mtl@section\l@section
\newenvironment{mytocenv}%
{\renewcommand*\l@section[2]{\mtl@section{{\color{red}##1}}{##2}}}%
{}
\makeatother
\begin{document}
\tableofcontents
\section{One}
Section one.
\begin{myenv}
\section{Two}
Section two.
\end{myenv}
\section{Three}
Section three.
\end{document}
Update I did not take care of subsection and so on (well that was not explicit in the question) so I think one should do
\makeatletter
\let\mtl@section\l@section
\let\mt@dottedtocline\@dottedtocline
\newenvironment{mytocenv}%
{\renewcommand*\l@section[2]{\mtl@section{{\color{red}##1}}{##2}}%
\renewcommand*\@dottedtocline[5]{\mt@dottedtocline{##1}{##2}{##3}{{\color{red}##4}}{##5}}}%
{}
\makeatother
You could also define a command instead of an environment; makes it easier IMO if you have consecutive sections which you want colored:
\documentclass{article}
\usepackage{xcolor,titlesec,titletoc}
\newcommand{\mystyle}[1][black]{%
\titleformat
{\section}%
{\normalfont\Large\bfseries\color{#1}}%
{\thesection}%
{1em}{}%
%
\titlecontents
{section}[0em]%
{\addvspace{0.3pc}\sffamily\bfseries\filright\color{#1}}%
{}{\hspace*{0em}}%
{\titlerule*[0.7pc]{.}\bfseries\contentspage}%
}
\mystyle
\begin{document}
\tableofcontents
\section{One}
Section one.
\mystyle[red]
\section{Two}
Section two.
\section{Three}
Section three.
\mystyle
\section{Four}
Section four.
\end{document}