Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7063221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:41:17+00:00 2026-05-28T04:41:17+00:00

I need to compute a SHA1 on a file that is changing often. I

  • 0

I need to compute a SHA1 on a file that is changing often. I can copy, paste, open the archive in Windows Explorer, but I get an UnauthorizedAccessException on the using instruction.. The exception suggests I have a read only file, which doesn’t seem to be true in the properties of the file.

The archive sits on a shared drive at a location that I have full access on.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;

namespace TheTest
{
    public class MakeSha1
    {
        static void Main(string[] args)
        {
            using (FileStream fs = new FileStream(@"###.xml.gz", FileMode.Open))
            {
                using (SHA1Managed sha1 = new SHA1Managed())
                {
                    byte[] hash = sha1.ComputeHash(fs);
                    StringBuilder formatted = new StringBuilder(hash.Length);
                    foreach (byte b in hash)
                    {
                        formatted.AppendFormat("{0:X2}", b);
                    }
                    Console.WriteLine(formatted.ToString());
                }
                Console.ReadKey();
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:41:18+00:00Added an answer on May 28, 2026 at 4:41 am

    The constructor you are using for FileStream does not explicitly specify file sharing, and so no file sharing is permitted by default. If the file is being modified frequently, then you might be better off using a different form of the constructor:

    using (fs = new FileStream(@"###.xml.gz", FileMode.Open, 
                               FileAccess.Read, FileShare.ReadWrite)
    {
        // ... your code here
    }
    

    Note that if another process modifies the file while you are processing, then your SHA1 will not be accurate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't find any PHP script to compute Krippendorff's Alpha . I need this
I'm working on a project(PHP Based) in which I need to compute SHA1, I'm
I need to compute combinatorials (nCr) in Python but cannot find the function to
I need to compute the sizes of some python objects, so I can break
I need to get the first 10mb of a file and compute md5 from
I need to compute destination path for a file before copying. If the path
I need to compute a hash that needs to be stable across architectures. Is
I need to compute the hash string that will match any future hash within
To solve some problem I need to compute a variant of the pascal's triangle
I need to develop a process that will detect if the users computer has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.