When someone files bankruptcy under any chapter, an "automatic stay" takes effect, which prevents anyone from taking any action to enforce a debt without the bankruptcy court's approval. That does not necessarily mean that the foreclosure will be cancelled. It may just be delayed. The lender will undoubtedly ask the court for "relief from stay" to go ahead with the foreclosure, but you have a right to object. You should immediately contact a bankruptcy attorney.
PLEASE BE ADVISED: This answer and any information contained herein is not intended to be treated, and should not be construed, as legal advice. Rather, this answer is offered solely for general information purposes. This answer does not create an attorney-client relationship, nor does it create any kind of legal relationship, duty, or privilege. This attorney is licensed only in Washington.
Upon filing a bankruptcy, civil cases against you will be stayed (put on hold). This will not offer permanent relief, though, as the party can then ask the bankruptcy court to lift the stay so they can proceed with the lawsuit.
You should contact a local bankruptcy attorney to discuss all of your options.